Y
Y
YeaNot2021-05-23 19:30:50
Python
YeaNot, 2021-05-23 19:30:50

How to limit sending in Telegram bot?

@bot.message_handler accepts a text message from the user and the bot sends back some messages.
But if the user writes something while sending , the bot will start to go crazy.
Is it possible to introduce a restriction so that the bot processes any other message only after it has performed all the necessary algorithms on the first message?

And if the user instantly sends 2 messages, can you make the bot process either only the 1st, or only the last one?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
o5a, 2021-05-25
@o5a

It’s hard to say something unambiguous without code, but you can set the status by users (at least just a dictionary with data). Processing has begun - set the status to the user that the request is being processed. And while the status is on, no other command is executed. When processing is completed, the status is reset. Conditionally:

user_status = {}

@bot.message_handler ...
def process_something(message):
    if user_status.get(message.from_user.id, 0) == 0:
        user_status[message.from_user.id] == 1
        start_our_process()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question