我试图在我的discord bot上制作一个集中的错误缺失参数,但它没有像我预期的那样工作,这是代码
@client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send(f"Se necesitan argumentos `!help {ctx}` para verlos")
在我看来,这应该像这个
这是必要的争论!帮助命令para verlos
但它看起来像这个
这是必要的争论!帮助<0x7fba169585b0处的discord.ext.commands.context.context对象>
如何使其看起来像第一种情况?
如果是集中的错误处理程序,则无法知道触发错误的命令。通过将<command_name>
作为字符串的一部分来通知用户
这里有一个例子:
@client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.MissingRequiredArguments):
await ctx.send('Se necesitan argumentos !help <command> para verlos')
<命令>是字符串的一部分。通过这种方式,您将通知用户传递command
参数,否则,该命令将不起作用。