Tuesday, 10 November 2020

"Ignoring exception in on_command_error" when I try to use my error handler with discord.py

I have added a simple error handler for any commands that have an argument to mention a channel. It will send an error message if you have mentioned an invalid channel. Here is the handler:

@bot.event
async def on_command_error(ctx, error):
    if isinstance(error, commands.ChannelNotFound):
        await ctx.send('Oops, thats not a channel!')
        return
    raise error

but instead of sending an error message, it puts this in the console:

Ignoring exception in on_command_error
Traceback (most recent call last):
  File "C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py", line 333, in _run_event
    await coro(*args, **kwargs)
  File "pogtato.py", line 39, in on_command_error
    raise error
  File "C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 851, in invoke
    await self.prepare(ctx)
  File "C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 786, in prepare
    await self._parse_arguments(ctx)
  File "C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 697, in _parse_arguments
    transformed = await self.transform(ctx, param)
  File "C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 552, in transform
    return await self.do_conversion(ctx, converter, argument, param)
  File "C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 505, in do_conversion
    return await self._actual_conversion(ctx, converter, argument, param)
  File "C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 451, in _actual_conversion
    ret = await instance.convert(ctx, argument)
  File "C:\Users\mmein\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\converter.py", line 321, in convert
    raise ChannelNotFound(argument)
discord.ext.commands.errors.ChannelNotFound: Channel "yes" not found.

Heres an example of a command that would raise the error:

@bot.command()
async def chantest(ctx, channel : TextChannel):
    await ctx.send(channel.id)

That command just prints out the id of a tagged channel, but should raise the error when I try to use the command without tagging a channel.

I don't know why this is happening, thanks in advance if you help.



from "Ignoring exception in on_command_error" when I try to use my error handler with discord.py

No comments:

Post a Comment