【问题标题】:Error message does not send (MissingPermissions, CommandNotFound)未发送错误消息(MissingPermissions、CommandNotFound)
【发布时间】:2021-08-02 05:15:39
【问题描述】:

导入不和谐 从 discord.ext 导入命令

类错误(commands.Cog):

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

@commands.Cog.listener()
async def on_ready(self):
    print ('Cog loaded: errors.py')

    if isinstance(error, commands.MissingRequiredArgument):
        await ctx.send(embed=embedVar)

@commands.Cog.listener()
async def command_not_found(self, ctx, error):
    embedVar = discord.Embed(title='**DEVELOPER**', description='Error occured:\n error.CommandNotFound', color=7419530)
    embedVar.add_field(name='**NOT PARSED**', value='Could not find command.')

    if isinstance(error, commands.CommandNotFound):
        await ctx.send(embed=embedVar)

@commands.Cog.listener()
async def on_permission_error(self, ctx, error):
    embedVar = discord.Embed(title='**DEVELOPER**', description='Error occured:\n error.MissingPermissions', color=7419530)
    embedVar.add_field(name='**NOT PARSED**', value='Missing required permissions.')

    if isinstance(error, commands.MissingPermissions):
        await ctx.send(embed=embedVar)

def 设置(客户端): client.add_cog(错误(客户端))

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    你不处理这样的错误......那些事件不存在。要处理错误,请使用 on_command_error 事件:

    @commands.Cog.listener()
    async def on_command_error(self, ctx, error):
       if isinstance(error, commands.CommandNotFound):
            # code for `CommandNotFound`
       elif isinstance(error, commands.MissingPermissions):
            ...
    

    【讨论】:

    • 非常感谢,我还以为活动多变哈哈。
    • 不,不是。如果有帮助,记得接受答案。
    猜你喜欢
    • 1970-01-01
    • 2015-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-18
    • 2021-03-01
    • 1970-01-01
    相关资源
    最近更新 更多