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

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

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

    1. discord.py 重写 |为我的命令出错

      时间:2023-10-10

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

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

              <tbody id='ZQoZy'></tbody>

                <legend id='ZQoZy'><style id='ZQoZy'><dir id='ZQoZy'><q id='ZQoZy'></q></dir></style></legend>

                <tfoot id='ZQoZy'></tfoot>
                本文介绍了discord.py 重写 |为我的命令出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                现在我完成了我的审核命令 [大部分],我正在尝试添加错误.我已经犯了请指定一个成员"错误,但我无法让机器人说这个成员不存在"输入无效名称时.

                Now that I finished my moderation commands [mostly], I am trying to add errors in. I already made the "please specify a member" error, but I cannot manage to make the bot say "this member does not exist" when an invalid name is input.

                @client.command(name='kick',
                            brief='Kicks user',
                            aliases=['Kick'],
                            pass_context=True)
                async def kick(context, member:discord.Member=None):
                # Errors
                if not member:
                    await context.send('Please specify a member.')
                    return
                # Actual Kicking
                if context.author.guild_permissions.kick_members == True:
                    await member.kick()
                    await context.send(f"{member.mention} was kicked ")
                else:
                    await context.send(context.message.author.mention + ", you don't have permission")
                

                这是我的命令之一,一切正常.如果该成员显然不存在,我想要一个显示找不到用户"的错误.例如,k!kick ijhguiserb 会让机器人说未找到成员",而不是在 shell 中给我一个错误.

                This is one of my commands, where everything is working. I would like an error which says "User not found" if the member, obviously, doesn't exist. For example, k!kick ijhguiserb would make the bot say, "Member not found," rather than giving me an error in the shell.

                我们将不胜感激,谢谢!

                Help would be appreciated, thanks!

                推荐答案

                你必须定义一个 错误处理程序来处理ConversionError

                You'll have to define an error handler to handle the ConversionError

                from discord.ext.commands import ConversionError
                
                @kick.error
                async def kick_error(ctx, error):
                    if isinstance(error, (ConversionError, BadArgument)):
                        await ctx.send("Member not found")
                    else:
                        raise error
                

                这篇关于discord.py 重写 |为我的命令出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Discord.py rewrite 如何 DM 命令? 下一篇:Discord.py 在 vc 中获取用户分钟数

                相关文章

                最新文章

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

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