Python discord.py中的错误处理问题

Python discord.py中的错误处理问题,python,discord.py,discord.py-rewrite,Python,Discord.py,Discord.py Rewrite,我试图用以下代码在我的discord python bot中创建错误消息: @purge.error async def clear_error(ctx, error): if isinstance(error, commands.MissingRequiredArgument): await ctx.send('Please specify the amount of messages you want to clear. Usage: //clear <numb

我试图用以下代码在我的discord python bot中创建错误消息:

@purge.error
async def clear_error(ctx, error):
    if isinstance(error, commands.MissingRequiredArgument):
        await ctx.send('Please specify the amount of messages you want to clear. Usage: //clear <number>')
    if isinstance(error, commands.MissingPermissions):
        await ctx.send('You do not have manage_messages permssion')

您的
@client.command
装饰器中缺少括号

尝试将其更改为
@client.command()
,您就可以开始了


参考资料:


    • 你必须这样做

      @client.event
      async def on_command_error(ctx, error):
          pass
      
      @client.command
      @commands.has_permissions(manage_messages=True)
      async def purge(ctx, amount : int):
          await ctx.channel.purge(limit=amount)
          await ctx.send('Done!')
      
      @purge.error
      async def clear_error(ctx, error):
          if isinstance(error, commands.MissingRequiredArgument):
              await ctx.send('Please specify the amount of messages you want to clear. Usage: //clear <number>')
          if isinstance(error, commands.MissingPermissions):
              await ctx.send('You do not have manage_messages permssion')
      
      @client.event
      命令上的异步定义错误(ctx,错误):
      通过
      @client.command
      @commands.has_权限(manage_messages=True)
      异步def清除(ctx,数量:int):
      等待ctx.channel.purge(限制=数量)
      等待ctx.send('Done!')
      @清除错误
      异步def清除_错误(ctx,错误):
      如果isinstance(错误,commands.MissingRequiredArgument):
      wait ctx.send('请指定要清除的邮件数量。用法://清除')
      如果isinstance(错误,commands.MissingPermissions):
      等待ctx.send('您没有管理\u消息权限')
      
      请为
      清除
      命令添加代码,好吗?到目前为止,我只能假设您没有向其添加
      @client.command()
      装饰器。
      @client.command
      @commands.has_permissions(manage_messages=True)
      async def purge(ctx, amount : int):
          await ctx.channel.purge(limit=amount)
          await ctx.send('Done!')
      
      @client.event
      async def on_command_error(ctx, error):
          pass
      
      @client.command
      @commands.has_permissions(manage_messages=True)
      async def purge(ctx, amount : int):
          await ctx.channel.purge(limit=amount)
          await ctx.send('Done!')
      
      @purge.error
      async def clear_error(ctx, error):
          if isinstance(error, commands.MissingRequiredArgument):
              await ctx.send('Please specify the amount of messages you want to clear. Usage: //clear <number>')
          if isinstance(error, commands.MissingPermissions):
              await ctx.send('You do not have manage_messages permssion')