Using Embeds
Last updated
Last updated
You will be using something called Discord embeds to make your responses look ever nicer! You can add a title to your message, a description, and a color off to the side.
We will be editing our hello command (below) which we had written previously to be like the image above.
We can delete the line await message.channel.send(f"Hello {message.authro.name}")
as we will be writing it from scratch to send it with an embed.
First, we need to create the actual embed we will be sending. This is a little different than sending a message like we did before as we will be needing to create the embed object . An object is like a container, think of a box, it contains a bunch of different things inside of it. An object will have a bunch of information about it inside of it.
So how do we create this object? Well, we can use a variable, lets called it embed. We can create a new embed by referencing the discord variable we created before and finding the premade Embed object. We can do this by typing embed = discord.Embed()
. Inside of the parenthesis, like how we did it before, we can include "settings". To properly format it, press enter between the 2 parenthesis. It should look something like this:
Now we can fill out the settings. The first thing is the title. In the example picture the word "Hello"
is the title. You can name this whatever you want, but for this case lets set it to "Hello"
. To do this we can type out (in the parenthesis) title = "Hello",
(make sure to include the comma after it).
Now we can add a description. In the example picture "Hello krishrenjen"
is the description. To do this is is pretty similar to adding a title except you change title to description. It would be as follows: description = f"Hello {message.author.name}",
(remember how we use f strings).
Now lets add a little color. In the example image there is a color bar on the left side of the embed. We can set this to any color we want. It is similar to how we did it before except with a slight twist. We can start with color =
like before but instead of typing the color we want, we have to do something different.
You have to use discord.Color.[color name](),
replacing [color name]
with the name of the color you want from the list below. For example, color = discord.Color.blue(),
.
A list of colors you can use (must be spelled exactly as what is shown below):
teal
dark_teal
brand_green
dark_green
blue
dark_blue
purple
dark_purple
magenta
gold
dark_gold
orange
dark_orange
brand_red
red
dark_red
lighter_gray
dark_gray
light_gray
darker_gray
blurple
fuchsia
yellow
Now all we need to do is send the embed. Use
Lets break this piece of code down. You use the await message.channel.send
to send a message to the channel. Then you use embed =
to show that you are sending an embed. Then after that you put what you called the embed, in this case we called it the same thing, embed
.
Only select the Final Code tab once you have completed your embed command. If you are stuck please see a mentor.
Your code should look something like the following at this point in the sushi card, except it will contain your custom commands:
Only select the Final Code tab once you have completed this section. If you are stuck please see a mentor.
If your code is not like this or is not working, please either read through the sushi card again OR come talk to one of the mentors who will guide you through the issue.