如何避免callback_query_handlers中出现不可调用列表错误?

问题描述 投票:0回答:1

我正在使用

telebot
制作一个电报机器人。该机器人必须使用按钮发送消息。为了处理回调数据,我使用
callback_query_handlers
,但是当我启动代码时Python显示这样的错误:

Traceback (most recent call last):
  File "C:\MY_FILE", line 124, in <module>
    @bot.callback_query_handlers(func=lambda call: True)
TypeError: 'list' object is not callable

这是代码:

import telebot
from telebot import types
bot = telebot.TeleBot("MY_TOKEN")
@bot.message_handler(commands=['show_buttons'])
def bar(message):
    markup = types.InlineKeyboardMarkup(row_width=2)
    button_m = types.InlineKeyboardButton('М', callback_data='cМ')
    button_i = types.InlineKeyboardButton('I', callback_data='cI')
    markup.add(button_m, button_i)
    bot.send_message(message.chat.id, text='SOME_TXT', reply_markup=markup)
@bot.message_handler(commands=['foo'])
def foo(message):
    bot.reply_to(message, 'foo')
@bot.callback_query_handlers(func=lambda call: True)
def answer(callback):
    print('It filters!')
    if callback.message:
        print('that works!')
bot.infinity_polling()
telegram telegram-bot python-3.9 telebot
1个回答
0
投票

您正在使用:

@bot.callback_query_handlers(func=lambda call: True)

但是正确的处理程序是:

@bot.callback_query_handler(func=lambda call: True)

所以它是单数,没有

s


如有疑问,我建议浏览官方示例

© www.soinside.com 2019 - 2024. All rights reserved.