@Mak_Sweet

NameError: name 'message' is not defined как решить?

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)
  • Вопрос задан
  • 986 просмотров
Пригласить эксперта
Ответы на вопрос 3
Musickk
@Musickk
Пёс
у тебя callback, значит место "message" ставь "call", всё просто :)
Ответ написан
Комментировать
donko1
@donko1
Изучаю python
Попробуй так, но если не поможет-то в какой строчке ошибка?
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)
Ответ написан
Комментировать
@Mak_Sweet Автор вопроса
line 32, in check
if i == bot.get_chat_member(chat_id=config.ID_CHANNEL, user_id=message.from_user.id).status:
NameError: name 'message' is not defined
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы