I am using pyTelegramBotAPI. I want to remove my Inline Keyboard Markup when a button response callback occurs. I do that in three ways:
- Editing the reply_markup message and passing a null array to the reply_markup argument:
bot.edit_message_reply_markup (call.message.chat.id, call.message.id, 'Example response', reply_markup = [])
- Deleting the message and sending a new one:
bot.delete_message (call.message.chat.id, call.message.id)
bot.send_message (call.message.chat.id, 'Example response.')
- Editing the message directly without reply_markup arguments:
bot.edit_message_text ('Example response.', call.message.chat.id, call.message.message_id)
They all work but when I press the button repeatedly before it disappears, the callback executes repeatedly, causing an error in all three ways, in the first and third when not able to edit message with same content. In the second when a message is already deleted.
How could I restrict the buttons to only be pressed once, or only sendg a callback, or the callback only allowing certain commands to be executed once, at least, until the Inline Keyboard Markup is shown again?
A global boolean variable that changes on button press is not an option as I have a lot of Inline Keyboard Markups that could be displayed simultaneously.
2
Answers
There is no option to limit call back query. If you need suggest to respective devs
Use a database to save the state of the button for the given user, with the expiration seconds you want. Then create an "if clicked" condition.