From 41c8c9d0ab1f9b007e6c7a3f341b6a3bb89482eb Mon Sep 17 00:00:00 2001 From: stijndcl Date: Tue, 20 Sep 2022 16:45:02 +0200 Subject: [PATCH] Put tracebacks in a codeblock for readability & to escape markdown --- didier/data/embeds/error_embed.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/didier/data/embeds/error_embed.py b/didier/data/embeds/error_embed.py index 9118c6d..03edd25 100644 --- a/didier/data/embeds/error_embed.py +++ b/didier/data/embeds/error_embed.py @@ -23,12 +23,14 @@ def _get_traceback(exception: Exception) -> str: if line.strip(): error_string += "\n" - return abbreviate(error_string, Limits.EMBED_FIELD_VALUE_LENGTH) + return abbreviate(error_string, Limits.EMBED_FIELD_VALUE_LENGTH - 8) def create_error_embed(ctx: commands.Context, exception: Exception) -> discord.Embed: """Create an embed for the traceback of an exception""" - description = _get_traceback(exception) + # Wrap the traceback in a codeblock for readability + description = _get_traceback(exception).strip() + description = f"```\n{description}\n```" if ctx.guild is None: origin = "DM" @@ -40,7 +42,7 @@ def create_error_embed(ctx: commands.Context, exception: Exception) -> discord.E embed = discord.Embed(title="Error", colour=discord.Colour.red()) embed.add_field(name="Command", value=f"{ctx.message.content}", inline=True) embed.add_field(name="Context", value=invocation, inline=True) - embed.add_field(name="Exception", value=abbreviate(str(exception), Limits.EMBED_FIELD_VALUE_LENGTH), inline=False) + embed.add_field(name="Exception", value=str(exception), inline=False) embed.add_field(name="Traceback", value=description, inline=False) return embed