Answer the question
In order to leave comments, you need to log in
NameError: name 'message' is not defined how to solve?
import os
import telebot
import config
from telebot import types
if os.name == "nt":
os.system("cls")
else:
os.system("clear")
bot = telebot.TeleBot(config.TOKEN)
@bot.message_handler(commands=['start'])
def start(message):
sub = telebot.types.InlineKeyboardMarkup()
sub.add(telebot.types.InlineKeyboardButton("Подписаться - 1", callback_data="Sub1", url=config.URL_CHANNEL))
sub.add(telebot.types.InlineKeyboardButton("Проверить", callback_data="check_sub"))
bot.send_message(message.chat.id, text="Приветствую тебя <b>{0.first_name}</b>!\nПеред началом нужно подписаться на канал что-бы получить доступ!".format(message.from_user, bot.get_me()), reply_markup=sub ,
parse_mode="html")
@bot.callback_query_handler(func=lambda call: True)
def check(call):
if call.data == "check_sub":
status = ['creator', 'administrator', 'member']
for i in status:
if i == bot.get_chat_member(chat_id=config.ID_CHANNEL, user_id=message.from_user.id).status:
chat_id = message.chat.id
bot.send_message(chat_id, "Проверка прошла успешно")
break
else:
chat_id = message.chat.id
bot.send_message(chat_id, text = "Проверка не пройдена")
bot.polling(none_stop=True)
Answer the question
In order to leave comments, you need to log in
you have a callback, so the place "message" put "call", everything is simple :)
Try this, but if it doesn't help, what line is the error in?
import os
import telebot
import config
from telebot import types
if os.name == "nt":
os.system("cls")
else:
os.system("clear")
bot = telebot.TeleBot(config.TOKEN)
@bot.message_handler(commands=['start'])
def start(message):
sub = telebot.types.InlineKeyboardMarkup()
sub.add(telebot.types.InlineKeyboardButton("Подписаться - 1", callback_data="Sub1", url=config.URL_CHANNEL))
sub.add(telebot.types.InlineKeyboardButton("Проверить", callback_data="check_sub"))
bot.send_message(message.chat.id, text="Приветствую тебя <b>{0.first_name}</b>!\nПеред началом нужно подписаться на канал что-бы получить доступ!".format(message.from_user, bot.get_me()), reply_markup=sub ,
parse_mode="html")
@bot.callback_query_handler(func=lambda call: True)
def check(call):
if call.data == "check_sub":
status = ['creator', 'administrator', 'member']
for i in status:
if i == bot.get_chat_member(chat_id=config.ID_CHANNEL, user_id=message.from_user.id).status:
chat_id = call.message.chat.id
bot.send_message(chat_id, "Проверка прошла успешно")
break
else:
chat_id = call.message.chat.id
bot.send_message(chat_id, text = "Проверка не пройдена")
bot.polling(none_stop=True)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question