-1

I have this command:

if message.content.lower().startswith("!activate"):
    if message.author.id not in tempo:
        await Bot.send_message(message.channel, "{} used the command".format(message.author.name))
        tempo.append(message.author.id)
        await asyncio.sleep(720)
        tempo.remove(message.author.id)
    else:
        await Bot.send_message(message.channel, "wait {} hours.".format(asyncio.sleep))

I would like every time the person tried to use the command a second time, show how much time is left before they can use it again, something like: "wait 4 hours and 50 minutes."

what should I do?

nosklo
  • 217,122
  • 57
  • 293
  • 297
Lucas Tesch
  • 137
  • 1
  • 10

1 Answers1

1

You can just store the time and calculate the remaining yourself:

import time
tempo = {} # use a dict to store the time

if message.content.lower().startswith("!activate"):
    if message.author.id not in tempo:
        await Bot.send_message(message.channel, "{} used the command".format(
            message.author.name))
        tempo[message.author.id] = time.time() + 720 # store end time
        await asyncio.sleep(720)
        del tempo[message.author.id]
    else:
        await Bot.send_message(message.channel, "wait {} seconds.".format(
            tempo[message.author.id] - time.time()))
nosklo
  • 217,122
  • 57
  • 293
  • 297
  • there is a way to show me the time in hours minutes seconds ? like: 2 hours, 35 minutes e 49 seconds. – Lucas Tesch Jul 02 '18 at 13:25
  • @LucasTesch just calculate it! you have the number of seconds... You can divide by 60 and 3600, or just use datetime module https://stackoverflow.com/questions/775049/how-to-convert-seconds-to-hours-minutes-and-seconds – nosklo Jul 02 '18 at 17:35