Embeds
This tutorial will walk you through the process of creating and posting message embeds.
Creating Embeds
An embed is a way to post messages to Discord with advanced formatting options. We can include things like titles, description, author, border color, etc. The bot allows you to reply with an embed using functions like respond
or sendMessage
. Here is an example of creating an embed with a few pieces of information:
The builtin function hexToInt
accepts hex strings of the format “0x….”, “#…”, or just a string of hex with no leading marker and converts them to int64. Here is what it could look like:
Including Author
We can incorporate other pieces of information by using a field like Author which accepts objects of type EmbedAuthor
. This type accepts a Name and an IconURL, and we can make use of the builtin .AvatarURL
member function to convert the user’s avatar to a valid Discord URL that we can use and scale it up/down accordingly.
Here is what it looks like now:
Including Thumbnail
Now we can extend the code again to add in the Thumbnail field. This field accepts objects of type EmbedThumbnail
which allows for a URL, width and height. We can use the same approach we used for Author to get a URL for the thumbnail, only this time a bit larger.
Here’s what it looks like with thumbnail included:
Other Fields
There are other fields allowed. Here is a table with a full listing:
type Embed
.URL | String | optional | |
.Title | String | optional | |
.Description | String | optional | |
.Timestamp | String | optional | |
.Color | int | optional | Integer value of a hex color |
.Footer | EmbedFooter | optional | |
.Image | EmbedImage | optional | |
.Thumbnail | EmbedThumbnail | optional | |
.Video | EmbedVideo | optional | |
.Provider | EmbedProvider | optional | |
.Author | EmbedAuthor | optional | |
.Fields | Array[EmbedField] | optional |