Embeds

Embed templates that can be used to send messages. These functions will generate embeds and send them to the desired target.

Example

Here is an example for sending a success message within a Pycord application command.

import ezcord

bot = ezcord.Bot()

@bot.slash_command()
async def hey(ctx: ezcord.EzContext):
    await ctx.success("Success!")

In any other case, the interaction must be passes to the template method.

class ExampleView(discord.ui.View):
    @discord.ui.button(label="Click here")
    async def button_callback(self, button, interaction):
        await emb.success(interaction, "Success!")
ezcord.emb.set_embed_templates(*, error_embed=None, success_embed=None, warn_embed=None, info_embed=None, **kwargs)[source]

Override the default embeds with custom ones.

This must be called before the first embed template is used. The description of the embeds will be replaced with the given text.

If you pass a string, error messages will be sent as a text instead of an embed. If the string is empty, the text will be taken from template methods.

Note

You can use the following variables for embed templates. They will automatically be replaced when the template is sent to an interaction.

  • {user} - The user who initiated the interaction

  • {username} - The name of the user

  • {user_mention} - The user mention

  • {user_id} - The ID of the user

  • {user_avatar} - The URL of the user’s avatar

Server variables will be replaced with information about the bot if the interaction was initiated in DMs.

  • {servername} - The guild where the interaction was initiated

  • {server_icon} - The URL of the guild’s icon

Bot variables will be replaced with information about the bot.

  • {guild_count} - Number of servers the bot is in

  • {user_count} - Number of users the bot can see

  • {cmd_count} - Number of application commands

Parameters:
  • error_embed (Embed | str | None) – The embed to use for error messages.

  • success_embed (Embed | str | None) – The embed to use for success messages.

  • warn_embed (Embed | str | None) – The embed to use for warning messages.

  • info_embed (Embed | str | None) – The embed to use for info messages.

  • **kwargs (Embed) – Additional embed templates. Can be used with send().

Example

from ezcord import emb

embed = discord.Embed(
    title="Error",
    color=discord.Color.orange()
)
emb.set_embed_templates(error_embed=embed)
async ezcord.emb.error(target, txt=None, *, title=None, edit=False, ephemeral=True, **kwargs)[source]

Send an error message. By default, this is a red embed.

Parameters:
  • target (Interaction | Messageable) – The target to send the message to.

  • txt (str | None) – The text for the embed description. If this is None, you need to provide a non-empty Embed when using set_embed_templates().

  • title (str | None) – The title of the embed. Defaults to None.

  • edit (bool) – Whether to edit the last message instead of sending a new one. Defaults to False.

  • ephemeral (bool) – Whether the message should be ephemeral. Defaults to True.

  • **kwargs – Additional keyword arguments for discord.abc.Messageable.send().

Return type:

discord.Interaction | discord.Message | None

async ezcord.emb.success(target, txt=None, *, title=None, edit=False, ephemeral=True, **kwargs)[source]

Send a success message. By default, this is a green embed.

Parameters:
  • target (Interaction | Messageable) – The target to send the message to.

  • txt (str | None) – The text for the embed description. If this is None, you need to provide a non-empty Embed when using set_embed_templates().

  • title (str | None) – The title of the embed. Defaults to None.

  • edit (bool) – Whether to edit the last message instead of sending a new one. Defaults to False.

  • ephemeral (bool) – Whether the message should be ephemeral. Defaults to True.

  • **kwargs – Additional keyword arguments for discord.abc.Messageable.send().

Return type:

discord.Interaction | discord.Message | None

async ezcord.emb.warn(target, txt=None, *, title=None, edit=False, ephemeral=True, **kwargs)[source]

Send a warning message. By default, this is a golden embed.

Parameters:
  • target (Interaction | Messageable) – The target to send the message to.

  • txt (str | None) – The text for the embed description. If this is None, you need to provide a non-empty Embed when using set_embed_templates().

  • title (str | None) – The title of the embed. Defaults to None.

  • edit (bool) – Whether to edit the last message instead of sending a new one. Defaults to False.

  • ephemeral (bool) – Whether the message should be ephemeral. Defaults to True.

  • **kwargs – Additional keyword arguments for discord.abc.Messageable.send().

Return type:

discord.Interaction | discord.Message | None

async ezcord.emb.info(target, txt=None, *, title=None, edit=False, ephemeral=True, **kwargs)[source]

Send an info message. By default, this is a blue embed.

Parameters:
  • target (Interaction | Messageable) – The target to send the message to.

  • txt (str | None) – The text for the embed description. If this is None, you need to provide a non-empty Embed when using set_embed_templates().

  • title (str | None) – The title of the embed. Defaults to None.

  • edit (bool) – Whether to edit the last message instead of sending a new one. Defaults to False.

  • ephemeral (bool) – Whether the message should be ephemeral. Defaults to True.

  • **kwargs – Additional keyword arguments for discord.abc.Messageable.send().

Return type:

discord.Interaction | discord.Message | None

async ezcord.emb.send(template, target, txt=None, *, title=None, edit=False, ephemeral=True, **kwargs)[source]

Send a custom embed template. This needs to be set up with set_embed_templates().

Parameters:
  • template (str) – The name of the template that was used in set_embed_templates().

  • target (Interaction | Messageable) – The target to send the message to.

  • txt (str | None) – The text for the embed description. If this is None, you need to provide a non-empty Embed when using set_embed_templates().

  • title (str | None) – The title of the embed. Defaults to None.

  • edit (bool) – Whether to edit the last message instead of sending a new one. Defaults to False.

  • ephemeral (bool) – Whether the message should be ephemeral. Defaults to True.

  • **kwargs – Additional keyword arguments for discord.abc.Messageable.send().

Return type:

discord.Interaction | discord.Message | None

class ezcord.emb.EzContext(bot, interaction)[source]

A custom context to access embed templates. Only works within Pycord application commands.

async error(msg, **kwargs)[source]
async success(msg, **kwargs)[source]
async warn(msg, **kwargs)[source]
async info(msg, **kwargs)[source]
t(key, count=None, **kwargs)[source]