D
D
Danil Sheblov2020-03-11 21:53:24
Python
Danil Sheblov, 2020-03-11 21:53:24

How can I make sure that a certain function can be entered once at a certain time?

Hello, I am a beginner programmer, I am writing my bot in VK (vk_api) using Python3.
I would like to ask a question.
I want to add the "Bonus" command, but I need users to be able to enter this command once every 24 hours, how to do it?..
I used the time module, and the time.sleep() function in the module, but as you understand, this stops the entire program, is it possible to make the user enter a command once at a certain time (eg 24 hours)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
yamudaqq, 2020-03-11
@yamudaqq

Convert the time of the last receipt of the bonus to unixtime, write this value for each user to the database, and with the subsequent message "Bonus", let the program receive the real time value and also translate it into unixtime. Farther

if (unixtime_currently - unixtime_old) >  86400:
  givebonus()
else:
  sendmessage('Для получения бонуса нужно подождать ещё'+need_time) # и здесь отправить время, которое нужно подождать для получения бонуса. узнать его можно так же через разницу во времени и потом делением на 60 итд.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question