Skip to content

Commit 70142c4

Browse files
author
Cyteon
committed
improve traceback in general errors
1 parent 043ae4c commit 70142c4

File tree

2 files changed

+57
-37
lines changed

2 files changed

+57
-37
lines changed

bot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def __init__(self) -> None:
9191
)
9292
self.logger = logger
9393
self.config = config
94-
self.version = "2.1.1"
94+
self.version = "2.1.2"
9595
self.start_time = time.time()
9696
self.prefixDB = prefixDB
9797
self.statsDB = statsDB

utils/ErrorLogger.py

+56-36
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,44 @@
1515
with open(f"./config.json") as file:
1616
config = json.load(file)
1717

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+
1856
async def command_error(error, context):
1957
async with aiohttp.ClientSession() as session:
2058
command_error_webhook = Webhook.from_url(config["command_error_webhook"], session=session)
@@ -25,44 +63,10 @@ async def command_error(error, context):
2563
color=discord.Color.red()
2664
)
2765

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)
6467

6568
await command_error_webhook.send(embed=embed, username = "PotatoBot - Error Logger")
69+
6670
async def error(self, event_method, *args, **kwargs):
6771
async with aiohttp.ClientSession() as session:
6872
error_webhook = Webhook.from_url(config["error_webhooks"], session=session)
@@ -79,4 +83,20 @@ async def error(self, event_method, *args, **kwargs):
7983
inline=False
8084
)
8185

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+
82102
await error_webhook.send(embed=embed, username="PotatoBot - Error Logger")

0 commit comments

Comments
 (0)