Answer the question
In order to leave comments, you need to log in
How to close buttons after clicking through Aiogram?
You need to change the code so that the "Text1" button closes after clicking and sending the message. Through reply_markup=types.ReplyKeyboardRemove it is not possible to do it, or I prescribe it in the wrong place.
@dp.message_handler(commands="game")
async def cmd_game(message: types.Message):
keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
buttons = ["текст1", "текст2"]
keyboard.add(*buttons)
await message.answer("Выбирайте нажатием на кнопку!", reply_markup=keyboard)
@dp.message_handler(lambda message: message.text == "текст1")
async def d(message: types.Message):
button1 = types.InlineKeyboardButton("Продолжить", callback_data="restart")
keyboard = types.InlineKeyboardMarkup().add(button1)
await message.answer(await get_random_question(), reply_markup=keyboard)
@dp.callback_query_handler()
async def ycallback(callback_query: types.CallbackQuery):
if callback_query.data == "restart":
await bot.delete_message(chat_id=callback_query.message.chat.id, message_id=callback_query.message.message_id)
await cmd_game(callback_query.message)
async def get_random_question():
with open("путь") as f:
content = f.readlines()
content = [x.strip() for x in content]
return random.choice(content)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question