Discord.py Err0r处理程序

时间:2020-11-11 06:03:55

标签: python discord discord.py

我有这个错误处理函数:

@clear.error
async def clear_error(error, ctx):
    if isinstance(error, MissingPermissions):
        await ctx.send(f'Sorry {ctx.author.mention}, you do not have permissions to do that!')

向阿卜杜勒阿齐兹(Abdulaziz)致谢,阿卜杜拉齐兹向我发送了此

但这不起作用

1 个答案:

答案 0 :(得分:0)

首先,您需要从commands导入discord.ext。然后,将if isinstance(error, MissingPermissions):替换为if isinstance(error, commands.MissingPermissions):

代码应如下所示:

from discord.ext import commands

@clear.error
async def clear_error(error, ctx):
    if isinstance(error, commands.MissingPermissions):
        await ctx.send(f'Sorry {ctx.author.mention}, you do not have permissions to do that!')```