• <bdo id='5BCQ1'></bdo><ul id='5BCQ1'></ul>

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

      <small id='5BCQ1'></small><noframes id='5BCQ1'>

      <tfoot id='5BCQ1'></tfoot>

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

        如何响应 discord.py 中的错误用户命令

        How to respond to wrong user command in discord.py(如何响应 discord.py 中的错误用户命令)

          1. <tfoot id='DPeXK'></tfoot>
              <tbody id='DPeXK'></tbody>

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

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

                  本文介绍了如何响应 discord.py 中的错误用户命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  如果用户键入 /foo 并且该命令不存在,我如何发送消息说该命令不存在"?

                  If user types /foo and that command does not exist, how do I send the message saying "This command does not exist"?

                  这可能很简单,但我有点困惑.

                  This is maybe pretty simple but I'm bit confused.

                  如果您需要更多信息,请发表评论.

                  If you need more info please comment.

                  谢谢!

                  推荐答案

                  你可以定义一个 on_command_error 事件(请注意,与记录的重写分支相比,异步分支上的参数顺序相反)如果出现 CommandError ,将被调用.

                  You can define an on_command_error event (Note that the order of arguments is reversed on the async branch, compared to the documented rewrite branch) that will be called if there if a CommandError is raised.

                  然后您可以签入 错误处理程序 如果错误是 CommandNotFound 错误并相应处理:

                  You can then check in that error handler if the error is a CommandNotFound error and handle it accordingly:

                  @bot.event
                  async def on_command_error(error, ctx):
                      if isinstance(error, commands.CommandNotFound):
                          await bot.send_message(ctx.message.channel, "No such command")
                      else:
                          raise error
                  

                  这假设您正在使用 discord.ext.commands 扩展来编写命令(您应该这样做).

                  This assumes you are using the discord.ext.commands extension to write your commands (which you should).

                  这篇关于如何响应 discord.py 中的错误用户命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  【网站声明】本站部分内容来源于互联网,旨在帮助大家更快的解决问题,如果有图片或者内容侵犯了您的权益,请联系我们删除处理,感谢您的支持!

                  相关文档推荐

                  How to make a discord bot that gives roles in Python?(如何制作一个在 Python 中提供角色的不和谐机器人?)
                  Discord bot isn#39;t responding to commands(Discord 机器人没有响应命令)
                  Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“关于我吗?Discord 机器人的功能?(不和谐.py))
                  message.channel.id Discord PY(message.channel.id Discord PY)
                  How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 机器人?)
                  discord.py - Automaticaly Change an Role Color(discord.py - 自动更改角色颜色)
                  <legend id='DKGwM'><style id='DKGwM'><dir id='DKGwM'><q id='DKGwM'></q></dir></style></legend>

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

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

                          <tfoot id='DKGwM'></tfoot>