• <bdo id='U8G88'></bdo><ul id='U8G88'></ul>
      <legend id='U8G88'><style id='U8G88'><dir id='U8G88'><q id='U8G88'></q></dir></style></legend>

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

        无法在聊天中显示错误

        时间:2023-10-10

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

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

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

                <legend id='pySuK'><style id='pySuK'><dir id='pySuK'><q id='pySuK'></q></dir></style></legend>
                  <tbody id='pySuK'></tbody>
              2. <i id='pySuK'><tr id='pySuK'><dt id='pySuK'><q id='pySuK'><span id='pySuK'><b id='pySuK'><form id='pySuK'><ins id='pySuK'></ins><ul id='pySuK'></ul><sub id='pySuK'></sub></form><legend id='pySuK'></legend><bdo id='pySuK'><pre id='pySuK'><center id='pySuK'></center></pre></bdo></b><th id='pySuK'></th></span></q></dt></tr></i><div id='pySuK'><tfoot id='pySuK'></tfoot><dl id='pySuK'><fieldset id='pySuK'></fieldset></dl></div>
                  本文介绍了无法在聊天中显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我试图让我的机器人通过吐出您没有权限{}来告诉用户是否有错误但是当我尝试使用此代码时:

                  I'm trying to make my bot tell a user if there is a error by spitting out You do not have the permissions {} But when I try to use this code:

                  @client.command(pass_context = True)
                  async def ban(ctx, member : discord.Member, *, content: str):
                      if ctx.message.author == client.user:
                          return
                      if ctx.message.author.server_permissions.administrator:
                          msg = (str(member) + "has been banned for" + str(content)).format(ctx.message)
                          await client.send_message(member, content)
                          await client.ban(member)
                          await client.send_message(ctx.message.channel, msg)
                  @ban.error
                  async def ban_error(error, ctx):
                      if isinstance(error, CheckFailure):
                          msg = "Sorry but you do not have the permissions {}".format(ctx.message.author.mention)  
                          await client.send_message(ctx.message.channel, msg)
                  

                  discord bot dms 用户,python 控制台中没有错误,如果我删除 @ban.error 片段,我会得到一个权限错误太低.

                  The discord bot dms the user and there is no errors in the python console and if I remove the @ban.error piece I get a too low of a permission error.

                  推荐答案

                  CheckFailure 只有在 检查 失败.您的代码中没有检查,所以这永远不会发生.您可以使用 if 语句转换为检查.commands.has_permissions" rel="nofollow noreferrer">commands.has_permission:

                  CheckFailure only gets raised if a check fails. There are no checks in your code, so this never happens. You can convert your if statement to a check very easily using commands.has_permission:

                  @client.command(pass_context = True)
                  @has_permissions(administrator=True)
                  async def ban(ctx, member : discord.Member, *, content: str):
                      msg = "{} has been banned for {}".format(ctx.message.author.mention, content)
                      await client.send_message(member, content)
                      await client.ban(member)
                      await client.send_message(ctx.message.channel, msg)
                  

                  错误处理程序可能会隐藏有价值的错误信息.我们可以只调用内置错误处理的机器人来处理任何其他不是 CheckFailures

                  It may be the case that the error handler is suppressing valuable error information. We can just call the bots built in error handling for any other errors that are not CheckFailures

                  from discord.ext.commands import CheckFailure
                  from discord import Forbidden
                  
                  
                  @ban.error
                  async def ban_error(error, ctx):
                      if isinstance(error, CheckFailure):
                          msg = "Sorry but you do not have the permissions {}".format(ctx.message.author.mention)  
                          await client.send_message(ctx.message.channel, msg)
                      elif isinstance(error, Forbidden):
                          await client.send_message(ctx.message.channel, "I do not have the correct permissions")
                      else:
                          print(error)
                          await client.on_command_error(error, ctx)
                  

                  这篇关于无法在聊天中显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Discord.py - 使用特定消息回复 DM 下一篇:我如何将成员的图像和昵称放在嵌入中?(w/discor

                  相关文章

                  最新文章

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

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

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