试图让机器人说出错误处理程序缺少什么参数

时间:2021-05-20 16:38:42

标签: python discord discord.py

我试图让我的机器人说出 cog 文件的错误处理程序中缺少什么参数。我查看了 API 并尝试过,但出现错误,File "/home/runner/Ultimate-Bot/cogs/Commands.py", line 35, in on_command_error missing_argument = error.missing_argument AttributeError: 'MissingRequiredArgument' object has no attribute 'missing_argument'

这是我的代码,

if isinstance(error, commands.MissingRequiredArgument):
        missing_argument = error.missing_argument
        await ctx.send(f"{ctx.author.mention}, Sorry, you forgot to type an important argument! `Missing Argument: {missing_argument}`")

注意:我正在一个 cog 文件中写这个。

1 个答案:

答案 0 :(得分:2)

您可以使用error.param.name

示例:

if isinstance(error, commands.MissingRequiredArgument):
    await ctx.send(f"{ctx.author.mention}, Sorry, you forgot to type an important argument! `Missing Argument: {error.param.name}`")