繁体   English   中英

discord.py 重写 - 使用 @ 处理错误<command> .error 给出一个 TypeError

[英]discord.py rewrite - Error Handling with @<command>.error gives a TypeError

我试图用这段代码进行错误处理

@mute.error
async def mute_error(ctx, error):

它在运行时给了我这个 TypeError

TypeError: mute_error() takes 2 positional arguments but 3 were given

我认为这个错误是由这两行引起的,但如果不是这里是错误处理代码的 rest:

@mute.error
async def mute_error(ctx, error):
    if isinstance(error, commands.MissingPermissions):
        await ctx.send(f'{ctx.message.author.mention} You do not have the permission to run that command! :red_circle:')
    elif isinstance(error, commands.MissingRequiredArgument):
        await ctx.send(f'{ctx.message.author.mention} There is an Argument missing in that command! :red_circle:\nMute Command Syntax: wm>mute @user [reason]')
    elif isinstance(error, commands.BadArgument):
        await ctx.send(f'{ctx.message.author.mention} To mute someone you need to mention them! :red_circle:\nMute Command Syntax: wm>mute @user [reason]')
    else:
        await ctx.send('There was an error while executing the command! xxLandiPlayz has been informed! :red_circle:')
        print(error)

它也在 Cog 内部,在 Mod class 内部

class Mod(commands.Cog):

def __init__(self, bot):
    self.bot = bot

我在这里做错了什么?
提前致谢!

当我使用它时,我在selferror之后有第一个参数,第二个是ctx 如果您在使用参数时遇到一些问题,您可以使用相同的参数顺序。

对于您的问题,如果您在 class 中使用此方法可能会有所帮助:

@mute.error
async def mute_error(self, error, ctx):

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM