2

I'm trying to make a discord bot where you can type 'iq math' and it sends a random math question. I want a delay so that if a user types 'iq math' and answers correctly or wrong it makes a delay so that the user have to wait 24 hours before the user can use 'iq math' again. The problem is when I start the delay it waits until it is finished for example:

users[user]['math']['timer'] = wait24hours()

print('You can now ask a math question again.')

It waits until 24 hours has passed after that it prints 'You can now ask a math question again.'

How do I fix this?

vsp0
  • 67
  • 4
  • instead of `timer`, store `users[user][topic][timestamp]`. Then when the user asks any question, you take the present timestamp of the question, compare it to the timestamp that user asked a question on that same topic from `[user][topic][timestamp]`, and then give them a new question or a message to wait longer before asking another question for `topic` based on the time elapsed – Max Power Dec 22 '19 at 16:29
  • 2
    ok thats actually an pretty good idea thank you ill see if this works thanks :) – vsp0 Dec 22 '19 at 16:34
  • after you try it out let me know if it works? If so I'll add it as an 'answer' here and you can accept. Or if you hit another issue with that let me know and I'll update/elaborate to try and help out – Max Power Dec 22 '19 at 16:38
  • 2
    of course I'll try that :) – vsp0 Dec 22 '19 at 16:40
  • 2
    this works you can make this an answer now :) thanks again – vsp0 Dec 22 '19 at 16:47
  • If you're using the commadns extension, you can use `command.cooldown`: https://stackoverflow.com/questions/58736488/add-cooldown-to-commanddiscord-py – Patrick Haugh Dec 23 '19 at 04:16
  • can you make an answer with this ? @PatrickHaugh – vsp0 Dec 30 '19 at 16:33

1 Answers1

0

instead of timer, store users[user][topic][timestamp] after each answer.

Then when the user asks any question, you take the present timestamp of the question, and compare it to the timestamp that user asked the last question on that same topic from [user][topic][timestamp].

Based on the time elapsed, you can either give them a new question or a message to wait longer.

Max Power
  • 8,265
  • 13
  • 50
  • 91