File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ async def load_cogs(self):
1616 await self .load_extension ("app.commands.kms" )
1717 await self .load_extension ("app.commands.link" )
1818 await self .load_extension ("app.commands.bancho" )
19+ await self .load_extension ("app.commands.errors" )
1920 await self .tree .sync ()
2021
2122def run ():
Original file line number Diff line number Diff line change 1+
2+ from discord .ext .commands import *
3+ from app .cog import BaseCog
4+
5+ class ErrorHandler (BaseCog ):
6+ @Cog .listener ()
7+ async def on_command_error (self , ctx : Context , error : CommandError ):
8+ if hasattr (ctx .command , "on_error" ):
9+ # Ignore errors that already have a local handler
10+ return
11+
12+ if isinstance (error , CommandNotFound ):
13+ return
14+
15+ elif isinstance (error , MissingRequiredArgument ):
16+ return await ctx .send (f"Missing argument: `{ error .param .name } `" )
17+
18+ elif isinstance (error , MissingPermissions ):
19+ return await ctx .send ("You don't have permission to use this command." )
20+
21+ elif isinstance (error , CommandOnCooldown ):
22+ return await ctx .send (
23+ f"This command is on cooldown. Try again in "
24+ f"{ error .retry_after :.1f} seconds."
25+ )
26+
27+ # Log unexpected errors
28+ self .logger .error (f'Unexpected error: { error } ' , exc_info = True )
29+ await ctx .send ("An unexpected error occurred." )
30+
31+ async def setup (bot : Bot ):
32+ await bot .add_cog (ErrorHandler ())
You can’t perform that action at this time.
0 commit comments