正在获取错误。discord.py中的CommandNotFound

问题描述 投票:-4回答:1

我正在编写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.' )
python discord.py
1个回答
0
投票

@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
© www.soinside.com 2019 - 2024. All rights reserved.