Answer the question
In order to leave comments, you need to log in
How to make two CallBack Handlers work in Telegram Bot in Python?
Good afternoon. I have two inlne keyboards in my telegram bot.
Both work separately in different files, or if one of them is replaced.
I tried to move one keyboard to another file, but the result is the same.
I understand that
this handler, which is in the code above, is trying to process the keyboard, which is in the code below.
Please help me figure it out. The keyboard code is pretty standard, for example the first one:
#Курсы валют
@bot.message_handler(regexp="Курсы валют")
def value_message(message):
keyboardV = types.InlineKeyboardMarkup()
kbv1 = types.InlineKeyboardButton(text="Доллар", callback_data="USD")
kbv2 = types.InlineKeyboardButton(text="Евро", callback_data="EUR")
kbv3 = types.InlineKeyboardButton(text="Фунт", callback_data="GBP")
keyboardV.add(kbv1, kbv2, kbv3)
bot.send_message(message.chat.id, "Выберите валюту: ", reply_markup=keyboardV)
@bot.message_handler(regexp="Новости")
def selectCounrty(message):
# Клавиатура выбора стран
keyboard = types.InlineKeyboardMarkup()
kb1 = types.InlineKeyboardButton(text="Россия", callback_data="country1")
kb2 = types.InlineKeyboardButton(text="Германия", callback_data="country2")
keyboard.add(kb1, kb2)
bot.send_message(message.chat.id, "Список стран: ", reply_markup=keyboard)
Answer the question
In order to leave comments, you need to log in
@bot.callback_query_handler(func=lambda call: True)
@bot.callback_query_handler(func=lambda call: call.data == "Data")
def callHandler1(call: CallbackQuery):
#Code
@bot.callback_query_handler(func=lambda call: call.data == "Data2")
def callHandler2(call: CallbackQuery):
#Code 2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question