Embeds

Embeds, or embed messages, are special messages that can only be sent by bots and webhooks that are in a special compartment with a lighter background and have a customizable color bar on the left.
This is what an embed message looks like:
embed_message
They have multiple arguments which are optional but it wouldn't really be an embed without some. The important ones we'll look at first are marked with a yellow star *.

We've already seen an embed in the first page, so let's learn how to use them:
First we look at a list of what arguments there are:

~ Title [Optional] *
~ Description [Optional] *
~ Color [Optional] - Default #000000 *
~ Footer [Optional]
~ Image [Optional]
~ Thumbnail [Optional]
~ Extra Field [Optional]

We'll go over each ticked argument (read these as all of the ticked ones contain necessary information) and the rest are gonna be a plus if you want to know more, but they aren't required for this guide.

Title


The title parameter gives the embed a bigger text on top, making it more visible and it's the first thing that comes to eye to the viewer, so it should contain very few and key words to be effective.
Titles like "Oh my gosh this is my first embed!" are probably not a good title and would be a better fit as a description, but this is just my advice.
To start we first create the embed variable inside a command:

@bot.command()
async def embed_message():
    embed = discord.Embed(
        title="Example Title" # This is the title!
    )
            

This is the starting point for the title and you can customize it to say whatever you want.

Description

To add a description, we just add a comma after title and we add a description parameter:

@bot.command()
async def embed_message():
    embed = discord.Embed(
        title="Example Title",
        description="Example Description" # This is the description!
    )
            

Now we added a description that you can also change at your liking. An important thing to note is that both are optional and if one is left out it won't display in the embed.
Let's proceed to add a color.

Color

To add a color, just like the description, we add a comma to the parameter above and we add the color parameter.
However, there's two ways to add a color. If your desired color is within the Discord Predefined Colors (You can look at a detailed list here), you can use discord.Color to express the color. For exmaple, if I want a red embed I'll use discord.Color.red() and if I want dark teal I'll use discord.Color.dark_teal().
Let's look at an example if your color is a predefined color:

@bot.command()
async def embed_message():
    embed = discord.Embed(
        title="Example Title",
        description="Example Description",
        color=discord.Color.red() # Red predefined color!
    )
            


Instead, if your color is a custom color you want to pick from, you must use hexadecimal color values. Let's make an example with red:

@bot.command()
async def embed_message():
    embed = discord.Embed(
        title="Example Title",
        description="Example Description",
        color=0xFF0000 # Red hexadecimal color!
    )
            

If you don't provide a color argument in the embed, the embed color will be pure black.

If you want to make your colors more vibrant, while Discord doesn't support gradients, you can make a function outside of the command to pick a random color from the predefined list of Discord Colors or with custom color hexadecimal codes and use that as the embed color to ensure random colors at each embed, or add a command parameter color to make the user choose the color instead of hard-coding it.

Now, to send your embed, we can start coding the method to send a normal reply to the command by the bot, but instead of making the response a text within quotes "", we type embed=embed. It would look like this in classic commands: await ctx.send(embed=embed) and like this in slash commands: await ctx.respond(embed=embed).

Other parameters

Footer

The footer allows you to display text at the very bottom of the embed in tiny text, so it shouldn't be important text, but rather something like the username of the user who executed the command, a timestamp, something like that. Here's an image of a footer:
footer

To add a footer, we can use the set_footer method outside of the embed. Footers also allow an icon that will display next to it. Like this:


@bot.command()
async def embed_message():
    embed = discord.Embed(
        title="Example Title",
        description="Example Description",
        color=discord.Color.red()
    )

    embed.set_footer(text="This is a footer", icon_url="https://example.com/icon.png")
        

Image

Displays an image in the embed.

Image

Image allow you to add, well, an image to your embed that will be displayed under the text. This can be used as decoration or a banner for dividing the embed into easily recognizable sections.
To set an image, add this outside of the embed: embed.set_image(url="https://example.com/icon.png"). Example:


@bot.command()
async def embed_message():
    embed = discord.Embed(
        title="Example Title",
        description="Example Description",
        color=discord.Color.red()
    )

    embed.set_image(url="https://example.com/icon.png")
            

Thumbnail

Displays a thumbnail in the embed.

Thumbnail

A thumbnail, displayed on the top right of the embed, is a smaller image usually used to display profile pictures or icons rather than big images. It can be used for example to display the command author's profile picture or get the profile of a server member.
To add a thumbnail, outside of the embed add this code: embed.set_thumbnail(url="https://example.com/icon.png"). Example:


@bot.command()
async def embed_message():
    embed = discord.Embed(
        title="Example Title",
        description="Example Description",
        color=discord.Color.red()
    )

    embed.set_thumbnail(url="https://example.com/icon.png")
            

Extra Field

Adds a text field to the embed.

Extra Field

Extra fields are text areas that are added to the embed to divide it into sections. They have a title and a description and, unlike other elements, you can add as many as you want. Fields also have another argument called inline which basically controls whether the field is displayed inline with others. This is the code to add a new embed field:


@bot.command()
async def embed_message():
    embed = discord.Embed(
        title="Example Title",
        description="Example Description",
        color=discord.Color.red()
    )

    embed.add_field(name="Example Field Title", value="Example Field Description", inline=False)
            


Arguments

As we've seen before, sometimes we talked about arguments that we added to commands, like in the role command that we made, we added the arguments member and role_name. Arguments are basically extra text in the command where the user can specify a value that can be used in the code. Arguments are an essential part of commands, basic ones too, so let's learn how to use them.

During the making of the role command, we saw how to add them and use them with classic commands. With slash commands, we add them the same way but this time the user knows what arguments are in the command thanks to Discord displaying them both on mobile and on desktop.

Arguments can be of various types, from built-in python types:

~ Strings (str)
~ Integers (int)
~ Booleans (bool)

Strings are text snippets that need to be closed inside brackets (" " or ' ' or even """ """ for multi-line text paragraphs) in the code. On classic commands, on Discord, this take a different turn, in fact, one word words like "Apple" or "Fridge" can be left without brackets, but text with spaces, like "I just took this apple out of the fridge" would require brackets or only the first word, "I", would be taken. So, we leave the string parameter as the last parameter (in the code) and before it we add the * parameter just like we saw in the role command.
Slash commands don't have this problem as arguments are separated into their own section each so you don't need brackets while texting nor have to add the * parameter.

Integers are numbers. Not much to say about these.

Booleans are logic statements. These can only be True or False. This can be used for customization for example, like in a kick command we could add the notify boolean parameter that if set to True would notify the Staff team that someone kicked a member.

There are also arguments from the Discord API, like discord.Member used in the role command. These can be looked up in the documentation.
To add an argument to a command, after the decorator, we start making the function.


async def hello(ctx):
                

Instead of only typing ctx, we add a comma , then the name of the argument and then : followed by a space and the type of parameter. For example, a command with the parameters name (string) and count (integer) would be:

async def hello(ctx, name: str, count: int):
                


Arguments can also be made None to make them optional. To do this, after an argument we add a space followed by = None. Example:

async def hello(ctx, name: str, count: int = None):
                

In this scenario, name is required while count is optional. Remember to add counter measures in the code if it's left empty or the command will fail. For example, let's check if the count parameter is empty:

async def hello(ctx, name: str, count: int = None):
    
    if count is None:
        await ctx.send(f"You didn't specify a value for the count, {name}!")

If we want to stop a command from being run if an optional parameter is left empty is to use return. Simply type this instead or after await ctx.send(f"You didn't specify a value for the count, {name}!") to stop the command. A useful scenario is in classic commands where users don't know the arguments and if left out, you could remind them to fill out that argument.

This guide is under development!

We really appreciate your interest in this guide! We'll keep expanding this, so make sure to check back once in a while, and we're also announcing everything we add on our Discord server, you can join it in the home page of the website.

Below is the final chapter which is how to launch the bot. New chapters will appear before the final one. Let's dive into it!

Launching the bot

We're at the final chapter of our journey. You're probably eager to try out your new freshly made bot. Well, we're here for this.

However, before we can truly launch it, we must install the dependencies we used along the way and insert our Token.
So, right click inside the folder where your bot script is located. Do not do this inside of VS Code. Now click "Open terminal in this folder", this will open the Command Prompt. Then, simply type this command: pip install py-cord. This will install py-cord and allow us to launch our bot.

Now, go on the Discord Developer Portal and create a new application. Then, go on Bot and click on "Reset Token". This will generate a new token we can then add to the script. Remember to keep this private. If it's leaked just generate a new one on the Developer Portal.
In the script, if you remember, we added a TOKEN variable. It's time to replace that temporary text inside the brackets with your new token. Remember to keep it inside the brackets though.
Now, go at the very end of the script. This must be the final line.
Insert this: bot.run(TOKEN). This will make the bot run with your token and allow it to authenticate to Discord servers.

Now, we're truly ready. 3..2..1.. type this command into the terminal: python (yourbotsriptname).py. Replace the text inside the parenthesis with your actual script file name.
This should now display the text like we saw when making the first event and the bot should appear online along with the commands.