From ed2373260c3eb574b742abf2d55aed91848f9f3e Mon Sep 17 00:00:00 2001 From: Choco <94597336+ChocoMeow@users.noreply.github.com> Date: Tue, 27 Feb 2024 12:37:58 +0800 Subject: [PATCH] Added error handler --- function.py | 15 ++++----------- main.py | 3 ++- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/function.py b/function.py index e2526f1..06bffdb 100644 --- a/function.py +++ b/function.py @@ -44,6 +44,8 @@ USERS_BASE: dict[str, Any] = { 'inbox':[] } +ALLOWED_MENTIONS = discord.AllowedMentions().none() + #-------------- Vocard Functions -------------- def open_json(path: str) -> dict: try: @@ -156,17 +158,8 @@ async def send(ctx: Union[commands.Context, discord.Interaction], key: str, *par text = await get_lang(ctx.guild.id, key) text = text.format(*params) - message = None - - if isinstance(ctx, commands.Context): - message = await ctx.send(text, delete_after=delete_after, ephemeral=ephemeral, allowed_mentions=discord.AllowedMentions.none()) - else: - if ctx.response.is_done(): - await ctx.followup.send(text, delete_after=delete_after, ephemeral=ephemeral, allowed_mentions=discord.AllowedMentions.none()) - else: - await ctx.response.send_message(text, delete_after=delete_after, ephemeral=ephemeral, allowed_mentions=discord.AllowedMentions.none()) - - return message + send_func = ctx.send if isinstance(ctx, commands.Context) else (ctx.followup.send if ctx.response.is_done() else ctx.response.send_message) + return await send_func(text, delete_after=delete_after, ephemeral=ephemeral, allowed_mentions=ALLOWED_MENTIONS) async def update_db(db: AsyncIOMotorCollection, tempStore: dict, filter: dict, data: dict) -> bool: for mode, action in data.items(): diff --git a/main.py b/main.py index 7123dc8..324e7a8 100644 --- a/main.py +++ b/main.py @@ -103,7 +103,8 @@ class Vocard(commands.Bot): error = getattr(exception, 'original', exception) if ctx.interaction: error = getattr(error, 'original', error) - if isinstance(error, (commands.CommandNotFound, aiohttp.client_exceptions.ClientOSError)): + + if isinstance(error, (commands.CommandNotFound, aiohttp.client_exceptions.ClientOSError, discord.errors.NotFound)): return elif isinstance(error, (commands.CommandOnCooldown, commands.MissingPermissions, commands.RangeError, commands.BadArgument)):