From f68d8a20861eb851f2713b796f639b44ba6b16c0 Mon Sep 17 00:00:00 2001 From: Jerrie-Aries Date: Wed, 24 Aug 2022 14:10:48 +0000 Subject: [PATCH] Add `unhandled_by_cog` parameter to `ModmailBot.on_command_error`: - Resolve #3170 --- bot.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index 5b71c9bc71..6ea42499cb 100644 --- a/bot.py +++ b/bot.py @@ -1511,7 +1511,17 @@ async def on_error(self, event_method, *args, **kwargs): logger.error("Ignoring exception in %s.", event_method) logger.error("Unexpected exception:", exc_info=sys.exc_info()) - async def on_command_error(self, context, exception): + async def on_command_error( + self, context: commands.Context, exception: Exception, *, unhandled_by_cog: bool = False + ) -> None: + 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 + if isinstance(exception, (commands.BadArgument, commands.BadUnionArgument)): await context.typing() await context.send(embed=discord.Embed(color=self.error_color, description=str(exception)))