-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] ModmailBot.on_command_error
does not respect cog's cog_command_error
error handler.
#3170
Comments
This is due to how discord.py handles errors. The only thing I can imagine is that the bot checks if an error is not part of a plugin before processing it. You can check out how discord.py internally dispatches error events here |
I have a couple of suggestions. Suggested solutions: Solution 1: class ModmailBot(commands.Bot):
...
async def on_command_error(self, context, exception):
# this is to deal with command specific handlers, e.g. `@kick.error`, etc
command = context.command
if command and command.has_error_handler():
return
# this is to deal with the `async def cog_command_error` if it's even defined in the cog
cog = context.cog
if cog and cog.has_error_handler():
return
# the rest of the code This is the default implemantation of Solution 2: class ModmailBot(commands.Bot):
...
# add a new parameter `unhandled_by_cog` which default to `False`
async def on_command_error(self, context, exception, unhandled_by_cog=False):
if not unhandled_by_cog:
command = context.command
if command and command.has_error_handler():
return
cog = context.cog
if cog and cog.has_error_handler():
return
# the rest of the code Example in class MyPlugin(commands.Cog):
def __init__(self, bot):
self.bot = bot
async def cog_command_error(self, ctx, error):
handled = False
if isinstance(error, TypeError):
await ctx.send(str(error))
handled = True
elif isinstance(error, MyCustomException):
# do things
handled = True
# some other checks
# the error is not handled here so let the `ModmailBot.on_command_error` do its thing
if not handled:
await self.bot.on_command_error(ctx, error, unhandled_by_cog=True) Reference:
|
Bot Version
v4.0.0-dev16
How are you hosting Modmail?
Other
Error Logs
None
Screenshots
No response
Additional Information
[PLUGIN] Both cog's
cog_command_error
andModmailBot.on_command_error
handlers catch the same exception.Reproduce:
Create a plugin with a error handler.
Expected result:
The
ModmailBot.on_command_error
handler should not be called since the error has already been dealt with within the cog/plugin.Actual result:
Both
cog_command_error
andModmailBot.on_command_error
handlers catch the exception.And since
ModmailBot.on_command_error
doesn't handleTypeError
, the error is raised and traceback is printed on console.Error:
The text was updated successfully, but these errors were encountered: