15
15
with open (f"./config.json" ) as file :
16
16
config = json .load (file )
17
17
18
+ def apply_context_errors (embed , context , ignore_message = False ):
19
+ embed .add_field (
20
+ name = "Author" ,
21
+ value = f"{ context .author .mention } " ,
22
+ inline = True
23
+ )
24
+
25
+ if context .guild :
26
+ embed .add_field (
27
+ name = "Guild" ,
28
+ value = f"`{ context .guild .name } ` (`{ context .guild .id } `)" ,
29
+ inline = True
30
+ )
31
+
32
+ if context .command :
33
+ embed .add_field (
34
+ name = "Command" ,
35
+ value = f"`{ context .command .name } `" ,
36
+ inline = True
37
+ )
38
+
39
+ if context .message .content != "" and not ignore_message :
40
+ embed .add_field (
41
+ name = "Message" ,
42
+ value = f"```{ context .message .content } ```" ,
43
+ inline = True
44
+ )
45
+
46
+ if context .interaction :
47
+ options = context .interaction .data ["options" ]
48
+ options = json .dumps (options , indent = 2 )
49
+
50
+ embed .add_field (
51
+ name = "Interaction Options" ,
52
+ value = f"```{ options } ```" ,
53
+ inline = True
54
+ )
55
+
18
56
async def command_error (error , context ):
19
57
async with aiohttp .ClientSession () as session :
20
58
command_error_webhook = Webhook .from_url (config ["command_error_webhook" ], session = session )
@@ -25,44 +63,10 @@ async def command_error(error, context):
25
63
color = discord .Color .red ()
26
64
)
27
65
28
- embed .add_field (
29
- name = "Author" ,
30
- value = f"{ context .author .mention } " ,
31
- inline = True
32
- )
33
-
34
- if context .guild :
35
- embed .add_field (
36
- name = "Guild" ,
37
- value = f"`{ context .guild .name } ` (`{ context .guild .id } `)" ,
38
- inline = True
39
- )
40
-
41
- if context .command :
42
- embed .add_field (
43
- name = "Command" ,
44
- value = f"`{ context .command .name } `" ,
45
- inline = True
46
- )
47
-
48
- if context .message .content != "" :
49
- embed .add_field (
50
- name = "Message" ,
51
- value = f"```{ context .message .content } ```" ,
52
- inline = True
53
- )
54
-
55
- if context .interaction :
56
- options = context .interaction .data ["options" ]
57
- options = json .dumps (options , indent = 2 )
58
-
59
- embed .add_field (
60
- name = "Interaction Options" ,
61
- value = f"```{ options } ```" ,
62
- inline = True
63
- )
66
+ apply_context_errors (embed , context )
64
67
65
68
await command_error_webhook .send (embed = embed , username = "PotatoBot - Error Logger" )
69
+
66
70
async def error (self , event_method , * args , ** kwargs ):
67
71
async with aiohttp .ClientSession () as session :
68
72
error_webhook = Webhook .from_url (config ["error_webhooks" ], session = session )
@@ -79,4 +83,20 @@ async def error(self, event_method, *args, **kwargs):
79
83
inline = False
80
84
)
81
85
86
+ if args :
87
+ if isinstance (args [0 ], discord .ext .commands .Context ):
88
+ apply_context_errors (embed , args [0 ], ignore_message = True )
89
+ else :
90
+ embed .add_field (
91
+ name = "Args" ,
92
+ value = f"```{ args } ```" ,
93
+ inline = False
94
+ )
95
+
96
+ embed .add_field (
97
+ name = "Kwargs" ,
98
+ value = f"```{ kwargs } ```" ,
99
+ inline = False
100
+ )
101
+
82
102
await error_webhook .send (embed = embed , username = "PotatoBot - Error Logger" )
0 commit comments