Skip to content

Latest commit

 

History

History
177 lines (149 loc) · 8.77 KB

File metadata and controls

177 lines (149 loc) · 8.77 KB
title description
Embeds
Discord components used to present data with special formatting and structure.

import { DiscordInteraction, DiscordMessage, DiscordMessages, DiscordEmbed, DiscordEmbedField, DiscordEmbedFields, } from "discord-message-components/packages/react"; import "discord-message-components/packages/react/dist/style.css";

import DiscordComponent from "../../../src/components/DiscordComponent";

Embeds

Embeds are a Discord feature that allows applications to format their messages in cool embedded format, enabling your bot to lay out messages with a lot of text into neat fields.

The Pycord Guide is a detailed guide that explains how to use Pycord and all of its features. The Getting Started section explains how you can get a brand new bot created and running from scratch. Interactions with Pycord Pycord's various Extensions Other Popular Topics We have so much more! Just explore, and you will find everything you need. If you want another page added, open an issue on the GitHub. Created with 💖 by the Pycord Team & Contributors

Creating embeds is simple! Just create an instance of discord.Embed and edit it to your liking. Once you're done, send it!

import discord

bot = discord.Bot()

@bot.command()
async def hello(ctx):
    embed = discord.Embed(
        title="My Amazing Embed",
        description="Embeds are super easy, barely an inconvenience.",
        color=discord.Colour.blurple(), # Pycord provides a class with default colors you can choose from
    )
    embed.add_field(name="A Normal Field", value="A really nice field with some information. **The description as well as the fields support markdown!**")

    embed.add_field(name="Inline Field 1", value="Inline Field 1", inline=True)
    embed.add_field(name="Inline Field 2", value="Inline Field 2", inline=True)
    embed.add_field(name="Inline Field 3", value="Inline Field 3", inline=True)
 
    embed.set_footer(text="Footer! No markdown here.") # footers can have icons too
    embed.set_author(name="Pycord Team", icon_url="https://example.com/link-to-my-image.png")
    embed.set_thumbnail(url="https://example.com/link-to-my-thumbnail.png")
    embed.set_image(url="https://example.com/link-to-my-banner.png")
 
    await ctx.respond("Hello! Here's a cool embed.", embed=embed) # Send the embed with some text
 
bot.run("TOKEN")
hello
Hello! Here's a cool embed. Embeds are super easy, barely an inconvenience. A really nice field with some information. The description as well as the fields support markdown! Inline Field 1 Inline Field 2 Inline Field 3 Footer! No markdown here.

This simple command sends replies to a slash command with an embed. Let's break it down:

embed = discord.Embed(
        title="My Amazing Embed",
        description="Embeds are super easy, barely an inconvenience.",
        color=discord.Colour.blurple(),
    )

This command creates an embed. We use the Embed class to create an embed object with the title "My Amazing Embed", the description "Embeds are super easy, barely an inconvenience.", and the color blurple, Discord's main theme color.

discord.Colour is a class full of classmethods that return color values. While the official, documented name of this is discord.Colour, discord.Color works as well.

embed.add_field(title="A Normal Field", value="A really nice field with some information. **The description as well as the fields support markdown!**")
embed.add_field(title="Inline Field 1", value="Inline Field 1", inline=True)
embed.add_field(title="Inline Field 2", value="Inline Field 2", inline=True)
embed.add_field(title="Inline Field 3", value="Inline Field 3", inline=True)

This small section shows off embed fields. You can add up to 25 fields to embeds with the add_field method of the discord.Embed class. These consist of three keyword arguments: title, value, and inline. title and value are both required arguments, whereas inline is optional and defaults to False when not defined. The inline argument specifies whether or not space will be divided among the inline fields. There could be a mix of fields where inline has different values too.

embed.set_footer(text="Footer! No markdown here.") # footers can have icons too
embed.set_author(name="Pycord Team", icon_url="https://example.com/link-to-my-image.png")
embed.set_thumbnail(url="https://example.com/link-to-my-thumbnail.png")
embed.set_image(url="https://example.com/link-to-my-banner.png")

In this section, we're adding unique items to the embed. These items are:

  • Footer - With the set_footer() method, you can set a small footer that holds a message. This has text and icon_url kwargs.
  • Author - With the set_author method, you can set an author for the embed. This is a small text field at the top of the embed. This includes name, url and icon_url kwargs.
  • Thumbnail - With the set_thumbnail method, you can set a small image to reside at the top-right of the embed. This has a single url kwarg.
  • Image - With the set_image method, you can set an image to sit at the bottom of an embed. This has a single url kwarg.

There are a lot more methods and attributes you can use to configure embeds. Here, we just covered the basics. Also, remember that all of these values are not necessary in an embed. An embed may only contain a few of these. For example, only a description, a title and a description, and so on.

:::info Related Topics

:::