mirror of
https://github.com/UiO-Gaming/mustafa.git
synced 2026-11-05 13:56:48 +01:00
make embed templates compatible with discord interactions
This commit is contained in:
1 file changed
+24
-17
@@ -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
|
||||
Reference in new issue
Block a user