Skip to content

Commit

Permalink
Handle hybrid interaction contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
LightSage authored and lifehackerhansol committed Jul 16, 2023
1 parent c62cf08 commit ed540a2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
def create_error_embed(exc: Any, *, ctx: Optional[commands.Context] = None, interaction: Optional[discord.Interaction] = None) -> discord.Embed:
trace = "".join(traceback.format_exception(type(exc), value=exc, tb=exc.__traceback__, chain=False))
embed = discord.Embed(title="Unexpected exception", description=f"```py\n{trace}```", color=0xe50730)
interaction = interaction or getattr(ctx, "interaction", None)

if ctx:
if ctx and ctx.interaction is None:
embed.title += f" in command {ctx.command}"
channelfmt = ctx.channel.mention if ctx.guild else "Direct Message"
embed.add_field(name="Channel", value=channelfmt)
Expand All @@ -43,10 +44,13 @@ def create_error_embed(exc: Any, *, ctx: Optional[commands.Context] = None, inte
embed.title += " in interaction"
channelfmt = interaction.channel.mention if interaction.guild else "Direct Message"
embed.add_field(name="Channel", value=channelfmt)
if interaction.message.content:
if interaction.message is not None:
embed.add_field(name="Invocation", value=interaction.message.content)
embed.set_author(name=interaction.user.name, icon_url=interaction.user.display_avatar.url)

if ctx.interaction:
embed.add_field(name="Command", value=ctx.command)

embed.add_field(name="Exception Type", value=exc.__class__.__name__)
return embed

Expand Down

0 comments on commit ed540a2

Please sign in to comment.