skip to Main Content

I am using pyTelegramBotAPI. I want to remove my Inline Keyboard Markup when a button response callback occurs. I do that in three ways:

  1. 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 = [])
  1. 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.')
  1. 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


  1. There is no option to limit call back query. If you need suggest to respective devs

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search