<tfoot id='JxUpO'></tfoot>

      <bdo id='JxUpO'></bdo><ul id='JxUpO'></ul>

    <small id='JxUpO'></small><noframes id='JxUpO'>

      <legend id='JxUpO'><style id='JxUpO'><dir id='JxUpO'><q id='JxUpO'></q></dir></style></legend>
      <i id='JxUpO'><tr id='JxUpO'><dt id='JxUpO'><q id='JxUpO'><span id='JxUpO'><b id='JxUpO'><form id='JxUpO'><ins id='JxUpO'></ins><ul id='JxUpO'></ul><sub id='JxUpO'></sub></form><legend id='JxUpO'></legend><bdo id='JxUpO'><pre id='JxUpO'><center id='JxUpO'></center></pre></bdo></b><th id='JxUpO'></th></span></q></dt></tr></i><div id='JxUpO'><tfoot id='JxUpO'></tfoot><dl id='JxUpO'><fieldset id='JxUpO'></fieldset></dl></div>
    1. discord.py bot 获得命令的剩余冷却时间

      时间:2023-10-11

              <bdo id='CI2jh'></bdo><ul id='CI2jh'></ul>
              <tfoot id='CI2jh'></tfoot>
              <i id='CI2jh'><tr id='CI2jh'><dt id='CI2jh'><q id='CI2jh'><span id='CI2jh'><b id='CI2jh'><form id='CI2jh'><ins id='CI2jh'></ins><ul id='CI2jh'></ul><sub id='CI2jh'></sub></form><legend id='CI2jh'></legend><bdo id='CI2jh'><pre id='CI2jh'><center id='CI2jh'></center></pre></bdo></b><th id='CI2jh'></th></span></q></dt></tr></i><div id='CI2jh'><tfoot id='CI2jh'></tfoot><dl id='CI2jh'><fieldset id='CI2jh'></fieldset></dl></div>

              <small id='CI2jh'></small><noframes id='CI2jh'>

                  <tbody id='CI2jh'></tbody>
                <legend id='CI2jh'><style id='CI2jh'><dir id='CI2jh'><q id='CI2jh'></q></dir></style></legend>
                本文介绍了discord.py bot 获得命令的剩余冷却时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我正在开发一个基于 python 的不和谐机器人,它具有以下命令

                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>
                

                但是当用户达到命令的 30 秒速率限制时,它会将错误输出到 python shell

                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
                anerAppDataLocalProgramsPythonPython36libsite- 
                      packagesdiscordextcommandsot.py", line 846, in process_commands
                      yield from command.invoke(ctx)
                   File "C:Users
                anerAppDataLocalProgramsPythonPython36libsite- 
                      packagesdiscordextcommandscore.py", line 367, in invoke
                      yield from self.prepare(ctx)
                   File "C:Users
                anerAppDataLocalProgramsPythonPython36libsite- 
                      packagesdiscordextcommandscore.py", line 351, in prepare
                      raise CommandOnCooldown(bucket, retry_after)
                discord.ext.commands.errors.CommandOnCooldown: You are on cooldown. Try 
                again in 28.58s
                

                我想要做的是获得剩余的冷却时间并将其放入可以在不和谐中回复给用户的东西,例如'此命令限速,请在28.58s后重试'

                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.

                谢谢!

                推荐答案

                你需要写一个 错误处理程序 用于处理 CommandOnCooldown 错误并发送消息.

                You'll need to write an error handler for your command that handles the CommandOnCooldown error and sends the message.

                @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
                

                这篇关于discord.py bot 获得命令的剩余冷却时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:discord.py 中的命令冷却时间 下一篇:使用 discord.py 让机器人响应图像

                相关文章

                最新文章

                1. <legend id='TMuxF'><style id='TMuxF'><dir id='TMuxF'><q id='TMuxF'></q></dir></style></legend>

                  <tfoot id='TMuxF'></tfoot>
                2. <small id='TMuxF'></small><noframes id='TMuxF'>

                  <i id='TMuxF'><tr id='TMuxF'><dt id='TMuxF'><q id='TMuxF'><span id='TMuxF'><b id='TMuxF'><form id='TMuxF'><ins id='TMuxF'></ins><ul id='TMuxF'></ul><sub id='TMuxF'></sub></form><legend id='TMuxF'></legend><bdo id='TMuxF'><pre id='TMuxF'><center id='TMuxF'></center></pre></bdo></b><th id='TMuxF'></th></span></q></dt></tr></i><div id='TMuxF'><tfoot id='TMuxF'></tfoot><dl id='TMuxF'><fieldset id='TMuxF'></fieldset></dl></div>
                    <bdo id='TMuxF'></bdo><ul id='TMuxF'></ul>