Answer the question
In order to leave comments, you need to log in
How can a Discord bot in Python on Discord.py display an error about a command not found in the chat?
When running an unknown command, the bot writes to the running console:
Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "habr" is not found
I already did error handling with the kick command, but only one command is covered there.
How to output the .CommandNotFound error is not clear.
p.s. I found the answer. I publish to anyone who needs
# Command not found
@client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandNotFound):
await ctx.send(embed = discord.Embed(description = f'{ctx.author .name}, command not found!', color = discord.Color.red()))
Answer the question
In order to leave comments, you need to log in
If it's not too late here
@client.event
async def on_command_error(ctx, error):
if isinstance(error, commands.CommandNotFound ):
await ctx.send(embed = discord.Embed(description = f'** {ctx.author.name}, данной команды не существует.**', color=0x0c0c0c))
What is 'discord.ext.commands.errors.CommandNotFound' - is this an exception? (I have not worked with Discord)
If yes, then probably like this:
try:
тут код обработки команд
except discord.ext.commands.errors.CommandNotFound:
# Здесь код выполнится только при ошибке CommandNotFound
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question