Home > Mobile >  Discord.py Cooldown in Seconds
Discord.py Cooldown in Seconds

Time:10-24

Well, I have a command with a cooldown. It shows the cooldown in seconds, but I want it to be in hours:minutes:seconds. Since I'm still very new to Python. I need a little help. This is my Code:

@client.event
async def on_command_error(ctx, error):
    if isinstance(error, commands.BadArgument):
        await ctx.send("User existiert nicht!")
    if isinstance(error, commands.CommandOnCooldown):
        msg = f'**Du bist in einem Cooldown** Versuch es in {round(error.retry_after)} Sekunden erneut.'
        await ctx.send(msg)

CodePudding user response:

Suggested related question which very much applies to this

But, adapted to your use case with just a little bit of math (no extra imports):

msg = f'**Du bist in einem Cooldown** Versuch es in {error.retry_after // (60 * 60):02d}:{(error.retry_after // 60) % 60:02d}:{error.retry_after % 60:02d} erneut.'

Would result in

"**Du bist in einem Cooldown** Versuch es in 34:17:36 erneut."

with error.retry_after == 123456.

Assuming error.retry_after is an integer. If it's not, cast it to an integer first and store it in another variable that is then used for the math.

  • Related