From 5f8df3724212514640817b34c9c232a30e8eba88 Mon Sep 17 00:00:00 2001 From: Hannele Ruiz Date: Thu, 22 Jun 2023 00:29:29 -0400 Subject: [PATCH] Added catching for invalid responses --- leek/bot.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/leek/bot.py b/leek/bot.py index 6150c50..abf6286 100644 --- a/leek/bot.py +++ b/leek/bot.py @@ -10,7 +10,7 @@ import aiomysql from aiohttp.client import _RequestContextManager from aiomysql import Pool, Connection -from discord import AutoShardedBot, ApplicationContext, DiscordException, Embed, SlashCommand +from discord import AutoShardedBot, ApplicationContext, DiscordException, Embed, SlashCommand, NotFound from .localization import localize, get_default, get_localizations @@ -147,9 +147,14 @@ async def on_application_command_error(self, ctx: ApplicationContext, exception: if self.debug: info = traceback.format_exception(type(exception), exception, exception.__traceback__) text = "\n".join(info) - await ctx.respond(f"```\n{text}\n```", ephemeral=True) + message = f"```\n{text}\n```" else: - await ctx.respond(localize("BOT_EXCEPTION_OCURRED", ctx.locale), ephemeral=True) + message = localize("BOT_EXCEPTION_OCURRED", ctx.locale) + + try: + await ctx.respond(message, ephemeral=True) + except NotFound: + await ctx.send(message, delete_after=60) await super().on_application_command_error(ctx, exception)