From 80e8dc84bcd0a4503c07fc686e5ff4017afdb1eb Mon Sep 17 00:00:00 2001 From: Tagptroll1 Date: Mon, 24 Dec 2018 16:54:26 +0100 Subject: CommandNotFound exceptions will attempt tofind a valid tag before silently ignoring --- bot/cogs/events.py | 12 +++++++++--- bot/cogs/tags.py | 3 +++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/bot/cogs/events.py b/bot/cogs/events.py index 3537c850a..edfc6e579 100644 --- a/bot/cogs/events.py +++ b/bot/cogs/events.py @@ -3,8 +3,8 @@ import logging from discord import Colour, Embed, Member, Object from discord.ext.commands import ( BadArgument, Bot, BotMissingPermissions, - CommandError, CommandInvokeError, Context, - NoPrivateMessage, UserInputError + CommandError, CommandInvokeError, CommandNotFound, + Context, NoPrivateMessage, UserInputError ) from bot.cogs.modlog import ModLog @@ -121,7 +121,13 @@ class Events: log.debug(f"Command {command} has a local error handler, ignoring.") return - if isinstance(e, BadArgument): + if isinstance(e, CommandNotFound) and not hasattr(ctx, "invoked_from_error_handler"): + tags_get_command = self.bot.get_command("tags get") + ctx.invoked_from_error_handler = True + + # Return to not raise the exception + return await ctx.invoke(tags_get_command, tag_name=ctx.invoked_with) + elif isinstance(e, BadArgument): await ctx.send(f"Bad argument: {e}\n") await ctx.invoke(*help_command) elif isinstance(e, UserInputError): diff --git a/bot/cogs/tags.py b/bot/cogs/tags.py index a0ba7fdd1..b128b6de1 100644 --- a/bot/cogs/tags.py +++ b/bot/cogs/tags.py @@ -180,6 +180,9 @@ class Tags: if tag_data['image_url'] is not None: embed.set_image(url=tag_data['image_url']) + # If its invoked from error handler just ignore it. + elif hasattr(ctx, "invoked_from_error_handler"): + return # If not, prepare an error message. else: embed.colour = Colour.red() -- cgit v1.2.3