Answer the question
In order to leave comments, you need to log in
Why does callback_query_handler only process the last line?
I use the Aiogram library for telegram bots.
My telegram bot processes only one inline line, and it seems to me that only the last one.
Here is the code:
keyboard = types.InlineKeyboardMarkup()
foods = ['Бургер', 'Картофель', 'Куринные ножки']
for food in foods:
inline_btns = types.InlineKeyboardButton(food, callback_data=food)
keyboard.add(inline_btns)
@dp.callback_query_handler(lambda c: c.data == food)
async def process_callback(call: types.CallbackQuery):
await bot.edit_message_text(text=f"Нажата кнопка {food}", chat_id=call.message.chat.id,
message_id=call.message.message_id)
await message.answer("Выберите блюдо:", reply_markup=keyboard)
Answer the question
In order to leave comments, you need to log in
keyboard = types.InlineKeyboardMarkup()
foods = ['Burger', 'Potato', 'Chicken Legs']
for food in foods:
inline_btns = types.InlineKeyboardButton(food, callback_data=food)
keyboard.add(inline_btns)
@dp.callback_query_handler (lambda c: c.data == food)
async def process_callback(call: types.CallbackQuery):
await bot.edit_message_text(text=f"{food} button pressed", chat_id=call.message.chat.id,
message_id= call.message.message_id)
await message.answer("Select dish:", reply_markup=keyboard)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question