Added error handler

This commit is contained in:
Choco
2024-02-27 12:37:58 +08:00
parent 3ece3986fe
commit ed2373260c
2 changed files with 6 additions and 12 deletions

View File

@@ -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():

View File

@@ -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)):