我正在编写Discord机器人,并且遇到错误问题。我正在尝试解决这个问题。帮我做。我正在尝试在聊天中打印它。
@on_command_error.error
async def on_command_error( ctx, error ):
if isinstance( error, commands.CommandNotFound ):
await ctx.send( f'{ ctx.author.name } something went wrong, please try to write command ``.help`` to see all commands of server.' )
@on_command_error.error
表示您希望它成为名为on_command_error
的特定命令的错误处理程序的回调。这是行不通的(即使您确实有该名称的命令),因为仅当机器人能够识别出您正在尝试调用该命令时,才会调用特定于命令的错误处理程序。相反,您应该使用@bot.event
装饰器,以便可以设置在发生任何命令错误时调用此回调。
@bot.event
async def on_command_error( ctx, error ):
if isinstance( error, commands.CommandNotFound ):
await ctx.send( f'{ ctx.author.name } something went wrong, please try to write command ``.help`` to see all commands of server.' )
else:
raise error