• <tfoot id='C5Ujc'></tfoot>

    • <bdo id='C5Ujc'></bdo><ul id='C5Ujc'></ul>

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

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

        捕获 CommandOnCooldown 错误

        时间:2023-09-09

          <legend id='CgkWI'><style id='CgkWI'><dir id='CgkWI'><q id='CgkWI'></q></dir></style></legend>
            <tbody id='CgkWI'></tbody>
        1. <i id='CgkWI'><tr id='CgkWI'><dt id='CgkWI'><q id='CgkWI'><span id='CgkWI'><b id='CgkWI'><form id='CgkWI'><ins id='CgkWI'></ins><ul id='CgkWI'></ul><sub id='CgkWI'></sub></form><legend id='CgkWI'></legend><bdo id='CgkWI'><pre id='CgkWI'><center id='CgkWI'></center></pre></bdo></b><th id='CgkWI'></th></span></q></dt></tr></i><div id='CgkWI'><tfoot id='CgkWI'></tfoot><dl id='CgkWI'><fieldset id='CgkWI'></fieldset></dl></div>

              1. <tfoot id='CgkWI'></tfoot>

                • <bdo id='CgkWI'></bdo><ul id='CgkWI'></ul>

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

                  本文介绍了捕获 CommandOnCooldown 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在制作一个有冷却时间的不和谐机器人,并且我正在尝试制作一个事件,当 CommandOnCooldown 错误发生时,该机器人会告诉他们他们需要等待多长时间.这是我的代码,看起来一切正常,但它不知道 retry_after 是什么意思:

                  I am making a discord bot that has a cooldown and I am attempting to make an event that when the CommandOnCooldown Error occurs, the bot will DM them how much longer they have to wait. Here is my code and it all looks okay, but it doesn't know what retry_after means:

                  @bot.event
                  async def on_CommandOnCooldown():
                      await bot.send_message(ctx.message.channel, 'You are on cooldown. Try again in {:.2f}s'.format(retry_after))
                  
                  @bot.command(pass_context = True)
                  @commands.cooldown(1, 30, commands.BucketType.user)
                  async def getalt(ctx):
                      msg = ["a list of stuff"]
                      await bot.send_message(ctx.message.author, random.choice(msg))
                      await bot.send_message(ctx.message.channel, "Alt Has Been Seen To Your DMs")
                      await bot.purge_from(ctx.message.channel, limit=2)
                      await bot.send_message(ctx.message.author, "Please Wait 30 Seconds Before Using This Command Again. If you do not wait the full time then you won't be sent an alt.")
                  

                  我正在使用来自 https://git.radiobrony.fr/的参考资料MKody/discord.py/commit/cd0de57d13b15f709aaacf78ce611dd87e0784ce

                  推荐答案

                  这是使用 discord.py 时捕获异常的通用格式:

                  This is the general format for catching exceptions when using discord.py:

                  from discord.ext import commands
                  
                  bot = commands.Bot('$')
                  
                  @bot.event
                  async def on_command_error(ctx, error):
                      if isinstance(error, commands.CommandOnCooldown):
                          await ctx.send('This command is on a %.2fs cooldown' % error.retry_after)
                      raise error  # re-raise the error so all the errors will still show up in console
                    
                  
                  @commands.cooldown(1, 30)
                  @bot.command()
                  async def getalt(ctx):
                      await ctx.send('in getalt')
                  
                  bot.run('token')
                  

                  getalt 是命令,有 30 秒的冷却时间,被 on_command_error 事件捕获,依次向频道发送消息.如果您还有其他不清楚的地方,请参阅详细文档 这里.

                  The getalt is the command, which has a 30-second cooldown, is caught by the on_command_error event, in turns will send a message to the channel. If you have anything else that you’re unclear about, please refer to the detailed documentation here.

                  这篇关于捕获 CommandOnCooldown 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:discord.py 如何添加静音命令 下一篇:如何创建一个简单的机器人来自动响应包含某个

                  相关文章

                  最新文章

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

                    1. <small id='yIDfR'></small><noframes id='yIDfR'>

                    2. <tfoot id='yIDfR'></tfoot>