Answer the question
In order to leave comments, you need to log in
How to make an interval on a telegram bot command?
The user executes some command. If 5 seconds have not passed since the last request, the bot writes: wait so many seconds before executing the next command. using telebot
Answer the question
In order to leave comments, you need to log in
Good afternoon, to restrict certain commands, you need the threading module, the easiest way is:
import threading
def test()
#options
def thread2(): # Поток 2
thr2 = Thread(target=test)
thr2.start()
mes = event.object.message['text']
if mes == 'ваша_команда':
try:
test() #Пользователь один раз использует команду
time.sleep(5) #Лимит на 5 секунд
except:
pass
if __name__ == '__main__':
thread2()
The best solution is to record the time the command was last used. Here I answered how to make an interval of 1 hour. In your case, .hour needs to be changed to .second and 1 to 5.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question