'How can I set a cooldown for discord.py commands?

I am having trouble with setting cooldowns for my discord commands. I understand how, but I want to make a daily command and I could do 86400 seconds, but I would rather the error not saying "Wait ... seconds" and rather hours, and minutes.

This is what I'm using right now:

@commands.cooldown(1, 86400, commands.BucketType.user)


Solution 1:[1]

Hey there, if you want the error message for daily command to be in the format of hours and minutes, check this out: Since you have the amount of seconds, you can calculate the minutes and hours with division and using the modulus operator(%) which is the remainder:

    @cd.error

    async def cd_error(self, ctx, error):

      if isinstance(error, commands.CommandOnCooldown):

        #cooldown time
        time = round(error.retry_after)

        #calculating hours left
        hours = str(time // 3600)

        #calculating minutes left
        minutes = str(time % 3600)

        #Making sure the output does not include 0 hours
        if hours != "0":
          err_msg = f"You need to wait {hours} hours and {minutes} minutes before you can do that again!"
        else:
          err_msg = f"You need to wait {minutes} minutes before you can do that again!"
        await ctx.send(err_msg)

        @commands.cooldown(1, 86400, commands.BucketType.user)
          #daily reward goes here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Łukasz Kwieciński