我试图让我的机器人说出 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 文件中写这个。
答案 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}`")