Y
Y
yasegor2021-09-08 17:59:48
Python
yasegor, 2021-09-08 17:59:48

How to change the Inline menu in a message to another Inline menu (aiogram)?

In general, I want to make it so that when I click on the `Inline` button, I get the next `Inline` menu in the same message.

I have this code:

#bot.py

@dp.message_handler(text=['Магазин'])
async def shop(message: types.Message):
    await  message.answer("Выберите подраздел: ", reply_markup=kb.inline_kb_full2)


#keyboards.py

inline_btn_3 = InlineKeyboardButton('A', callback_data='A')
inline_btn_4 = InlineKeyboardButton('B', callback_data='B')
inline_btn_5 = InlineKeyboardButton('C', callback_data='C')
inline_kb_full2 = InlineKeyboardMarkup(row_width=1).add(inline_btn_3,inline_btn_4,inline_btn_5)


It is necessary that when I click on "A" I have the following menu:

inline_btn_6 = InlineKeyboardButton('1', switch_inline_query_current_chat='')
inline_btn_7 = InlineKeyboardButton('2', switch_inline_query_current_chat='')
inline_btn_8 = InlineKeyboardButton('3', switch_inline_query_current_chat='')
inline_btn_9 = InlineKeyboardButton('Назад ↩️',callback_data='Back')
inline_kb_full3 = InlineKeyboardMarkup(row_width=1).add(inline_btn_6,inline_btn_7,inline_btn_8,inline_btn_9)


What should I add to bot.py so that when one button in the menu is pressed, another menu will open?
PS: I am very weak in coding

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Mandzyuk, 2021-09-08
@Ryslan_13

@dp.message_handler(text=['Магазин'])
async def shop(message: types.Message):
  await message.answer("Выберите подраздел: ", reply_markup=inline_kb_full2)

@dp.callback_query_handler(lambda c: c.data == 'A')
async def process_callback_button1(callback_query: types.CallbackQuery):
    await bot.answer_callback_query(callback_query.id)
    await bot.send_message(callback_query.from_user.id, 'Нажата первая кнопка!', reply_markup=inline_kb_full3)

This code will do everything right
@dp.callback_query_handler(lambda c: c.data == 'A')
async def process_callback_button1(callback_query: types.CallbackQuery):
    await bot.answer_callback_query(callback_query.id)
    await bot.send_message(callback_query.from_user.id, 'Нажата первая кнопка!', reply_markup=inline_kb_full3)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question