File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
1
+ import logging
2
+
3
+ import discord
4
+ from discord .ext import commands
5
+ from datetime import datetime
6
+
7
+
8
+ logger = logging .getLogger (__name__ )
9
+
10
+
11
+ class error_handler (commands .Cog ):
12
+ def __init__ (self , bot ):
13
+ self .bot = bot
14
+
15
+ @commands .Cog .listener ()
16
+ async def on_application_command_error (self , ctx , error ):
17
+
18
+ # # This is just an interesting way of handling errors PER ERROR.
19
+ # # For now, let's just catch all and redirect to logs and channel
20
+ # if isinstance(error, commands.CommandOnCooldown):
21
+ # await ctx.respond("This command is currently on cooldown!")
22
+ # else:
23
+ # raise error # Here we raise other errors to ensure they aren't ignored
24
+
25
+ error_channel = self .bot .get_channel (self .bot .server_settings .log_channel ['zorak_log' ])
26
+
27
+ embed = discord .Embed (title = f':red_circle: Zorak error!'
28
+ , description = f'{ ctx .author } used /{ ctx .command } in <#{ ctx .channel } >'
29
+ , color = discord .Color .dark_red ()
30
+ , timestamp = datetime .utcnow ())
31
+ embed .add_field (name = 'Traceback (most recent call last): '
32
+ , value = f'{ error } ' )
33
+
34
+ await error_channel .send (ctx .author .mention )
35
+ await error_channel .send (embed = embed )
36
+ logger .critical (error )
37
+
38
+
39
+ def setup (bot ):
40
+ bot .add_cog (error_handler (bot ))
You can’t perform that action at this time.
0 commit comments