0

I added a command cooldown but how to make it for hours and minutes.

@bot.command(pass_context=True)
@commands.cooldown(1, 30, commands.BucketType.user)
async def ping(ctx):
    msg = "Pong {0.author.mention}".format(ctx.message)
    await bot.say(msg)
Demotry
  • 869
  • 4
  • 21
  • 40

1 Answers1

3

commands.cooldown's second argument, per takes an interval in seconds, you can easily convert your desired hours and minutes into seconds by multiplying by their equivalent in seconds (1 min = 60 sec, 1 hour = 3600 sec). You can also create a wrapper function that does the converting for you:

def cooldown(rate, per_sec=0, per_min=0, per_hour=0, type=commands.BucketType.default):
    return commands.cooldown(rate, per_sec + 60 * per_min + 3600 * per_hour, type)

@bot.command(pass_context=True)
@cooldown(1, per_min=5, per_hour=1, type=commands.BucketType.user)
async def ping(ctx):
    msg = "Pong {0.author.mention}".format(ctx.message)
    await bot.say(msg)

This will initiate a cooldown of 1 hour and 5 minutes.

Taku
  • 31,927
  • 11
  • 74
  • 85
  • @Demotry If you want to convert seconds to hours/minutes, look at [this question](https://stackoverflow.com/questions/775049/how-to-convert-seconds-to-hours-minutes-and-seconds) – Patrick Haugh Jun 12 '18 at 03:08
  • @abccd Ok i will ask in another question. – Demotry Jun 12 '18 at 04:37