discord.py bot getting cooldown time remaining of command

1 python discord discord.py

I'm working on a python based discord bot that has the following command

@client.command(name="Mine",
            description="Mine daily.",
            brief="Mine daily.",
            aliases=['mine', 'm'],
            pass_context=True)
@commands.cooldown(1, 30, commands.BucketType.user)
async def mine(ctx, arg):
   <content>
Run Code Online (Sandbox Code Playgroud)

But when users hit the 30 second rate limit of the command it outputs the error to the python shell

Ignoring exception in command Mine
Traceback (most recent call last):
   File "C:\Users\raner\AppData\Local\Programs\Python\Python36\lib\site- 
      packages\discord\ext\commands\bot.py", line 846, in process_commands
      yield from command.invoke(ctx)
   File "C:\Users\raner\AppData\Local\Programs\Python\Python36\lib\site- 
      packages\discord\ext\commands\core.py", line 367, in invoke
      yield from self.prepare(ctx)
   File "C:\Users\raner\AppData\Local\Programs\Python\Python36\lib\site- 
      packages\discord\ext\commands\core.py", line 351, in prepare
      raise CommandOnCooldown(bucket, retry_after)
discord.ext.commands.errors.CommandOnCooldown: You are on cooldown. Try 
again in 28.58s
Run Code Online (Sandbox Code Playgroud)

What I want to do is have something that gets the remaining cooldown and puts it into something that can be said back to the user on discord e.g. 'This command is ratelimited, please try again in 28.58s'

I haven't been able to find much help for this online, and most of it is outdated or doesn't seem to work.

Thanks!

Pat*_*ugh 5

您需要为您的命令编写一个错误处理程序来处理CommandOnCooldown错误并发送消息。

@mine.error
async def mine_error(ctx, error):
    if isinstance(error, commands.CommandOnCooldown):
        msg = 'This command is ratelimited, please try again in {:.2f}s'.format(error.retry_after)
        await ctx.send(msg)
    else:
        raise error
Run Code Online (Sandbox Code Playgroud)