@FoF4n

Нужно вызвать функцию check(call), написав в функции echo_message check(call) Выдает ошибку «NameError: name 'call' is not defined»?

@bot.message_handler(func=lambda message: True)
def echo_message(message):
    text = message.text
    global flag
    global filmCode
    chat_id = message.chat.id
    if flag == False:
        if text == "Бот":
            check /*ТУТ ВЫЗОВ ФУНКЦИИ*/
            bot.send_message(chat_id, "#", reply_markup=start_markup())
            
        else:
            check/*ТУТ ВЫЗОВ ФУНКЦИИ*/
            bot.send_message(chat_id, "#", reply_markup=start_markup())
    else:
        check/*ТУТ ВЫЗОВ ФУНКЦИИ*/


def check(call):
    status = ['creator', 'administrator', 'member']
    global flag
    for i in status:
        if i == bot.get_chat_member(chat_id="-1001983985312",user_id=call.message.chat.id).status:
            flag = True
            print(flag)
            check2(call)
            break
    else:
        bot.send_message(call.message.chat.id, "#", reply_markup=start_markup())
        flag = False
  • Вопрос задан
  • 43 просмотра
Решения вопроса 1
RimMirK
@RimMirK
Вроде человек. Вроде учусь. Вроде пайтону
check принимает почему-то callback_query. из message ты его никак не воьмешь. Из колбека ты только месседж используешь, так зачем тогда там колбек?

Если не брать во внимание весь остальной говнокод, то решение такое
@bot.message_handler(func=lambda message: True)
def echo_message(message):
    text = message.text
    global flag
    global filmCode
    chat_id = message.chat.id
    if flag == False:
        if text == "Бот":
+           check(message)
            bot.send_message(chat_id, "#", reply_markup=start_markup())
            
        else:
+           check(message)
            bot.send_message(chat_id, "#", reply_markup=start_markup())
    else:
+       check(message)


-def check(call):
+def check(message):
    status = ['creator', 'administrator', 'member']
    global flag
    for i in status:
-       if i == bot.get_chat_member(chat_id="-1001983985312",user_id=call.message.chat.id).status:
+       if i == bot.get_chat_member(chat_id="-1001983985312",user_id=message.chat.id).status:
            flag = True
            print(flag)
            check2(call)
            break
    else:
-       bot.send_message(call.message.chat.id, "#", reply_markup=start_markup())
+       bot.send_message(message.chat.id, "#", reply_markup=start_markup())
        flag = False
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

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

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