1

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)
Navis
  • 15
  • 7

1 Answers1

2

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.

TARN4T1ON
  • 522
  • 2
  • 12
  • ValueError: Unknown format code 'd' for object of type 'float' – Navis Oct 24 '21 at 11:21
  • Either follow the last paragraph of my answer or change the format code (```:02d```) to ```:02.0f``` which will truncate the decimal part of a floating point number string. – TARN4T1ON Oct 24 '21 at 11:26