P
P
Ponytno2022-03-07 20:39:13
Python
Ponytno, 2022-03-07 20:39:13

How to set a time limit for a command for a user in a VK bot?

It is necessary to make sure that a person cannot spam the bot with a command, it is necessary that there is some kind of timer, that is, a certain command can be called 5 times within 30 seconds, if more than 5 times, then this command is ignored. How to implement this using the example of this command:

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)
E
Elvis, 2022-03-07
@Ponytno

Save the access time to the database and subtract from the current time, if less than 5-6 seconds have passed, do nothing, otherwise execute the logic further.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question