Discord.py 找不到命令时如何发送消息?

Discord.py 找不到命令时如何发送消息?,discord.py,Discord.py,我试图在找不到命令但命令不起作用时发送消息: @client.event _ready()上的异步定义: 更改\u状态。开始() 打印(“-------------------------”) 打印(“登录为”) 打印(“用户名:%s”%client.user.name) 打印(“ID:%s”%client.user.ID) 打印(“-------------------------”) 异步def on_消息(ctx,错误): 如果isinstance(错误,commands.CommandN

我试图在找不到命令但命令不起作用时发送消息:

@client.event
_ready()上的异步定义:
更改\u状态。开始()
打印(“-------------------------”)
打印(“登录为”)
打印(“用户名:%s”%client.user.name)
打印(“ID:%s”%client.user.ID)
打印(“-------------------------”)
异步def on_消息(ctx,错误):
如果isinstance(错误,commands.CommandNotFound):
text=('Sorry{},此命令不存在,请检查$help以获取更详细的列表').format(ctx.author.提提)
msg=wait ctx.send(文本)
等待ctx.message.delete()
等待异步睡眠(5)
等待消息。删除()
其他:
通过
提出错误

您正在查找命令错误事件上的

@client.event
命令上的异步定义错误(ctx,错误):
如果isinstance(错误,commands.CommandNotFound):
等待ctx.send(“命令不存在”)
参考:


我找到了问题的答案,而不是通过客户端运行。事件装饰器,我通过客户端运行。听着,装饰器:

@client.event
_ready()上的异步定义:
更改\u状态。开始()
打印(“-------------------------”)
打印(“登录为”)
打印(“用户名:%s”%client.user.name)
打印(“ID:%s”%client.user.ID)
打印(“-------------------------”)
@client.listen()
命令上的异步定义错误(ctx,错误):
如果isinstance(错误,commands.CommandNotFound):
text=('Sorry{},此命令不存在,请检查$help以获取更详细的列表').format(ctx.author.提提)
msg=wait ctx.send(文本)
等待ctx.message.delete()
等待异步睡眠(5)
等待消息。删除()

当任何命令发生错误时,调用
on\u command\u error
事件。 在
on_command\u error
事件中,您可以检查错误是否是
CommandNotFound
的实例,该实例是在找不到键入的命令时抛出的,还是不存在。如果是这样,您可以向使用该命令的频道发送消息

@client.event
async def on_command_error(ctx, error):
    """Command error handler"""
    embed = discord.Embed(color=discord.Color.red())
    if isinstance(error, commands.CommandNotFound):
        embed.title = "Command not Found"
        embed.description = "Recheck what you've typed."
        #await ctx.send(embed=embed)

我试过了,但还是遇到了同样的问题。问题是什么?我已经完成了代码,但是当我运行一个不存在的命令时,它仍然会说找不到命令,即使它应该发送消息。您是否添加了装饰程序
客户端。事件