From 7fd9225d964ff90f972afd1e780ebb26df1a365c Mon Sep 17 00:00:00 2001 From: F4zii Date: Fri, 21 Feb 2020 21:10:00 +0200 Subject: Handling and logging CommandError the CommandError exception was ignored, We now catch the exception to handle and log the event Also added a little code reformat --- bot/cogs/error_handler.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/bot/cogs/error_handler.py b/bot/cogs/error_handler.py index 39b868e62..19d6e6946 100644 --- a/bot/cogs/error_handler.py +++ b/bot/cogs/error_handler.py @@ -108,16 +108,20 @@ class ErrorHandler(Cog): similar_command_name = similar_command_data[0] similar_command = self.bot.get_command(similar_command_name) - with contextlib.suppress(CommandError): - if similar_command.can_run(ctx): - misspelled_content = ctx.message.content - e = Embed() - e.set_author(name="Did you mean:", icon_url=Icons.questionmark) - e.description = f"{misspelled_content.replace(command_name, similar_command_name)}" - await ctx.send( - embed=e, - delete_after=7.0 - ) + log_msg = "Cancelling attempt to suggest a command due to failed checks." + try: + if not similar_command.can_run(ctx): + log.debug(log_msg) + return + except CommandError as cmd_error: + log.debug(log_msg) + await self.on_command_error(ctx, cmd_error) + + misspelled_content = ctx.message.content + e = Embed() + e.set_author(name="Did you mean:", icon_url=Icons.questionmark) + e.description = f"{misspelled_content.replace(command_name, similar_command_name)}" + await ctx.send(embed=e, delete_after=7.0) elif isinstance(e, BadArgument): await ctx.send(f"Bad argument: {e}\n") -- cgit v1.2.3