Search code examples
python-3.xpython-telegram-bot

Python-telegram-bot Inline keyboard disappear and reappear after action


I want to click a button on the inline keyboard, send a dice to the user, make the keyboard disappear so that the user can't mess with it while the dice is rolling and after the dice rolled I want to make it appear again. the code that I'm using to make the dice roll is when the user clicks on Roll dice it does:

value = await update.callback_query.message.reply_dice(update.effective_message.chat_id, emoji= '🏀')
dice_value = valore.dice.value

and the keyboard looks like this:

 keyboard_basketDemo = [
        [
            InlineKeyboardButton("⚙ Bet Settings 🍕", callback_data="SettingsDemoBet"),
            InlineKeyboardButton("Throw ball", callback_data="basketDemo"),
        ],
    ]

How can I be sure that the keyboard disappears and after the actions is complete it appears the same keyboard as before so that the user can then choose what he wants to do?


Solution

  • I used the

    await update.callback_query.edit_message_reply_markup()
    
    await update.callback_query.message.edit_text("My cards")
    

    to respectively hide the inline keyboard and change the header text. Then to create a new one I used await update.callback_query.message.reply_text("Choose an option: ", reply_markup=reply_markup) with the reply markup being a new keyboard created within the function