Error handling 我如何知道所使用的命令不和谐

Error handling 我如何知道所使用的命令不和谐,error-handling,discord,discord.py,embed,Error Handling,Discord,Discord.py,Embed,我正在尝试对我的Discord.py进行错误处理,我如何知道弹出错误时使用了什么命令 @bot.event async def on_command_error(ctx, error): print("error: ",error) if search("not found", str(error)): c_f = random.choice([f"`{command used}` was not found,

我正在尝试对我的Discord.py进行错误处理,我如何知道弹出错误时使用了什么命令

@bot.event
async def on_command_error(ctx, error):
    print("error: ",error)

    if search("not found", str(error)):
        c_f = random.choice([f"`{command used}` was not found, silly.", "Ehm.. Since when do we have `{command used}`?", "I don't know what `{command used}` is?"])
        embed=discord.Embed(title=c_f, description=f"Please use existing commands. {ctx.author.mention}", color=error_color)
        embed.timestamp = datetime.utcnow()
        embed.set_footer(text=bot_name, icon_url=icon_uri)
        await ctx.send(embed=embed)
    elif search("cooldown", str(error)):
        c_d = random.choice(["Did you drink energy drinks!?", "Why are you stressing, buddy.", "Duhh, wait, you're on cooldown!"])
        second_remain = round(error.retry_after, 1)
        embed=discord.Embed(title=c_d, description=f"Try again after {second_remain}s. {ctx.author.mention}", color=error_color)
        embed.timestamp = datetime.utcnow()
        embed.set_footer(text=bot_name, icon_url=icon_uri)
        await ctx.send(embed=embed)
    else:
        raise error

我可以使用的任何属性?

您的解决方案是将它们专门添加到命令中,这也意味着它可以通过更精确的命令帮助诊断问题

您还可以向特定的侦听器添加任何错误事件,就像您为所有命令添加错误事件一样,而不是单独添加错误事件

@bot.command()
异步定义命令名称(ctx):
# ...
@命令名错误
异步定义命令\u名称\u错误(ctx,错误):
如果isinstance(错误,commands.CommandInvokeError):
等待ctx.send(“此命令的错误”+错误)

使用
@command\u name.error
将命令名放在.error之前,如果该命令产生错误,则会生成该命令的错误侦听器。

您可以使用
ctx.command

@bot.event
命令上的异步定义错误(ctx,异常):
错误=getattr(异常,“原始”,异常)
if hasattr(ctx.command,“on_error”):#如果命令有自己的处理程序
返回
elif isinstance(错误,CommandNotFound):
返回
如果isinstance(错误,discord.CommandInvokeError):
打印(ctx.command)

我真的不想对我所有的命令都这么做,因为我有很多。我只想使用错误具有的属性(如果有)。在文档中似乎找不到任何错误。您只需将这些特定错误添加到可能引发错误的命令中即可。这不是命令,只有在触发
-dwadwa
等命令时才会发生此错误。因此,我可以将其添加到特定命令中,除非我需要数十亿行。我不使用cogs。更新了我的答案@Abdxrrahman