Python 3.13.2, pyTelegramBotAPI-4.27.0, Windows 10
I have a problem with Python telebot inline buttons. It worked fine for a long time, without any problems. At some point it stopped to work. I did not change the code. I tested even basic examples and have the same behavior - handler is not triggered.
Perhaps there is a way to debug this?
import telebot
from telebot import types
API_TOKEN = '0123456789:AaBbCcDdEe'
bot = telebot.TeleBot(API_TOKEN)
kb = types.InlineKeyboardMarkup(row_width=1)
btn_types = types.InlineKeyboardButton(text='label1', callback_data='btn_types')
kb.add(btn_types)
@bot.message_handler(commands=['start'])
def send_welcome(message):
bot.send_message(message.chat.id, "text", reply_markup=kb)
@bot.callback_query_handler(func=lambda call: True)
def answer(call):
print(call.data)
if call.data == 'btn_types':
bot.send_message(call.message.chat.id, "Button clicked")
if __name__ == '__main__':
bot.polling(none_stop=True)
Button shown, but on click nothing happens. At the same time, url inline button works fine. Plain buttons work fine as well...
What might happen?
Run bot, /start in Telegram, button shown. On button click, bot should respond with some action. However, nothing happens. In the example provided it should show chat message "Button clicked"
call.answer()? But either way, the fact that your print statement isn't being executed means that that entire callback function isn't being executed so it must be something to do with the decorator