1
@client.event
async def on_command_error(ctx,error):
  if isinstance(error , commands.CommandOnCooldown):
    await ctx.send(f'{ctx.author.mention}**hold your horses buddy <:iac_namaste:841266597318361098>**')
    await ctx.send('Try again in {:2f}s'.format(error.retry_after))

I have added cooldowns on one of my command for 20 min

@commands.cooldown(1 , 1200, type=commands.BucketType.user)

and it is working fine but I'm not getting the output in min or hr format

enter image description here

I want it to send something like try again in 20 min , and also show how many min's left

Hiresh Verma
  • 97
  • 3
  • 9
  • To get minutes from seconds you have to divide the seconds by 60. – Matthias Sep 13 '21 at 16:28
  • but how can I do that in a string – Hiresh Verma Sep 13 '21 at 16:30
  • `await ctx.send('Try again in {:2f} minutes'.format(error.retry_after / 60))`. I assume that `error.retry_after` is a number, otherwise you will have to use `float` to convert it to a number first. – Matthias Sep 13 '21 at 16:30
  • Does this answer your question? [How do I convert seconds to hours, minutes and seconds?](https://stackoverflow.com/questions/775049/how-do-i-convert-seconds-to-hours-minutes-and-seconds) – Wasi Master Sep 13 '21 at 16:32
  • @Matthias oh thanks for that ```await ctx.send('Try again in {:2f}m'.format((error.retry_after)/60))``` – Hiresh Verma Sep 13 '21 at 16:34

1 Answers1

2

The best way would be to just use the new discord timestamp format

import time  # Add this to the top

# Then in the error handler
await ctx.send('Try again in <t:{}:R>'.format(int(time.time() + error.retry_after)))
Wasi Master
  • 1,112
  • 2
  • 11
  • 22