D
D
Daniel2021-09-29 13:12:29
Python
Daniel, 2021-09-29 13:12:29

How to make the bot clean up unnecessary messages?

I have a bot that I want to make seamless, but the stumbling block is the user's ability to write any message and break the chain. Almost everything is tied to inline buttons, but there are also a couple of ordinary keyboard buttons, after which I see everything through delete_message to 1 message, and if the user writes something before cleaning, the bot will break. So the question is: How to make the bot wait for the message and delete it at the right time?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Daniel, 2021-09-30
@DanielWorker

The answer turned out to be eerily simple, if everything is properly adjusted at the moments when the user must enter text (ala "Enter your data"), this option is just right with a bang:

@bot.message_handler(content_types=['text'])
def delete(message):
    if message.text == message.text:
        bot.delete_message(message.chat.id, message.message_id)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question