Skip to content

Commit

Permalink
Check earlier if error is handled on command error
Browse files Browse the repository at this point in the history
  • Loading branch information
jackra1n committed Mar 19, 2024
1 parent e33bcd1 commit 6021f56
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions core/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ async def on_command_completion(self, ctx: commands.Context) -> None:
pass

async def on_command_error(self, ctx: commands.Context, error) -> None:
if hasattr(error, "is_handled"):
return
if isinstance(error, commands.CommandNotFound):
return
if not ctx.command:
Expand All @@ -80,10 +82,15 @@ async def on_command_error(self, ctx: commands.Context, error) -> None:
logger.error(f"[{ctx.command.qualified_name}] failed for [{ctx.author}] <-> [{error}]")
if isinstance(error, commands.CheckFailure):
await ctx.send("You do not have permission to use this command.")
if hasattr(error, "is_handled"):
return
if isinstance(error, commands.MissingRequiredArgument):
await ctx.send("A required argument is missing.")
return

try:
await ctx.message.add_reaction("❌")
except discord.errors.NotFound:
pass

ERRORS_CHANNEL_ID = 1219407043186659479
if ctx.guild:
Expand All @@ -93,10 +100,6 @@ async def on_command_error(self, ctx: commands.Context, error) -> None:
embed = discord.Embed(title=error_msg, description=f"```{error}```", color=discord.Color.red())
await self.get_channel(ERRORS_CHANNEL_ID).send(embed=embed)

try:
await ctx.message.add_reaction("❌")
except discord.errors.NotFound:
pass

async def close(self) -> None:
await self.db.pool.close()
Expand Down

0 comments on commit 6021f56

Please sign in to comment.