Put tracebacks in a codeblock for readability & to escape markdown

pull/133/head
stijndcl 2022-09-20 16:45:02 +02:00
parent 23edc51dbf
commit 41c8c9d0ab
1 changed files with 5 additions and 3 deletions

View File

@ -23,12 +23,14 @@ def _get_traceback(exception: Exception) -> str:
if line.strip(): if line.strip():
error_string += "\n" 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: def create_error_embed(ctx: commands.Context, exception: Exception) -> discord.Embed:
"""Create an embed for the traceback of an exception""" """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: if ctx.guild is None:
origin = "DM" 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 = discord.Embed(title="Error", colour=discord.Colour.red())
embed.add_field(name="Command", value=f"{ctx.message.content}", inline=True) 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="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) embed.add_field(name="Traceback", value=description, inline=False)
return embed return embed