Reputation: 623
Whenever a check returns false, I get this error:
Ignoring exception in command checkme:
Traceback (most recent call last):
File "/home/ade/.local/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 892, in invoke
await ctx.command.invoke(ctx)
File "/home/ade/.local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 790, in invoke
await self.prepare(ctx)
File "/home/ade/.local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 744, in prepare
raise CheckFailure('The check functions for command {0.qualified_name} failed.'.format(self))
discord.ext.commands.errors.CheckFailure: The check functions for command checkme failed.
Even with a check where its clearly not some other error with the check, such as this basic always-false command, I get the error. While it doesn't actually disturb the code, I was hoping to get a clean console that information/real errors could be printed to, and that wouldnt be clogged with this error. Is there a way to not raise this error?
def returnfalse(ctx):
return False
@bot.command(name='testcommand')
@commands.check(returnfalse)
def testcommand(ctx):
pass
Upvotes: 0
Views: 2171
Reputation: 131
If you are looking to have the check failure dismissed every time, I would suggest setting up an on_command_error
event.
In the main file:
@bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.errors.CheckFailure):
pass
else:
print('Ignoring exception in command {}:'.format(ctx.command), file=sys.stderr)
traceback.print_exception(type(error), error, error.__traceback__, file=sys.stderr)
Be sure to import traceback
and sys
. You will get every other error as intended, put the CheckFailure will be passed. If you remove the print
and traceback
from the else
statement, the on_command_error
will eat all of your errors.
Upvotes: 1