make embed templates compatible with discord interactions

This commit is contained in:
LBlend committed 2022-11-14 03:52:25 +01:00
1 parent 38870d1dae
commit ca8d768f22
1 file changed
+24 -17
+24 -17
View File
@@ -1,70 +1,77 @@
import discord
def default_footer(ctx: discord.ext.commands.Context, embed: discord.Embed) -> discord.Embed:
def default_footer(interaction: discord.Interaction, embed: discord.Embed) -> discord.Embed:
"""
Sets a footer containing the command invoker's name, discriminator and avatar
Parameters
-----------
ctx (discord.ext.commands.Context): The current Discord context
interaction (discord.Interaction): Discord interaction context
embed (discord.Embed): An embed object to add the footer to
Returns
-----------
(discord.Embed): The sent in embed + footer
(discord.Embed): The passed in embed + footer
"""
return embed.set_footer(icon_url=ctx.author.avatar, text=f"{ctx.author.name}#{ctx.author.discriminator}")
return embed.set_footer(
icon_url=interaction.user.avatar,
text=f"{interaction.user.name}#{interaction.user.discriminator}"
)
def error_warning(ctx: discord.ext.commands.Context, text: str) -> discord.Embed:
def error_warning(interaction: discord.Interaction, text: str) -> discord.Embed:
"""
Creates an embed with a specified error message based on a warning template
Parameters
-----------
ctx (discord.ext.commands.Context): The current Discord context
interaction (discord.Interaction): Discord interaction context
text (str): The error message
Returns
-----------
(discord.Embed): An embed object based on the template with the specified text
"""
embed = discord.Embed(color=discord.Color.gold(), description=f"⚠️ {text}")
default_footer(ctx, embed)
default_footer(interaction, embed)
return embed
def error_fatal(ctx: discord.ext.commands.Context, text: str) -> discord.Embed:
def error_fatal(interaction: discord.Interaction, text: str) -> discord.Embed:
"""
Creates an embed with a specified error message based on a warning template
Parameters
-----------
ctx (discord.ext.commands.Context): The current Discord context
interaction (discord.Interaction): Discord interaction context
text (str): The error message
Returns
-----------
(discord.Embed): An embed object based on the template with the specified text
"""
embed = discord.Embed(color=discord.Color.red(), description=f"❌ {text}")
default_footer(ctx, embed)
default_footer(interaction, embed)
return embed
def success(ctx: discord.ext.commands.Context, text: str) -> discord.Embed:
def success(interaction: discord.Interaction, text: str) -> discord.Embed:
"""
Creates an embed with a specified message using a template signifying success.
Parameters
-----------
ctx (discord.ext.commands.Context): The current Discord context
interaction (discord.Interaction): Discord interaction context
text (str): The message
Returns
-----------
discord.Embed: An embed object based on the template with the specified text
"""
embed = discord.Embed(color=discord.Color.green(), description=f"✅ {text}")
default_footer(ctx, embed)
default_footer(interaction, embed)
return embed