P
P
Ponytno2022-03-05 23:49:59
Python
Ponytno, 2022-03-05 23:49:59

How to set the interval for executing a VKontakte bot command?

I would like to know how to set a limit on the use of a command. So that the command can be executed 1 time in 10 seconds.

for event in longpoll.listen():
    if event.type == VkBotEventType.MESSAGE_NEW:
        if event.from_chat:
            user_message = event.object.message['text'].lower()            
            if user_message == '!привет':
                vk.messages.send(random_id = get_random_id(),
                    message = (f"@id{id} ( {first_name}), здарова крутыш"),
                    chat_id = event.chat_id)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Imaev, 2022-03-06
@AIRC24

You can just put in time.sleep(10). Just don't forget import time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question