# Embed preview
here is an exemplar of how an implant may look. We will go over embed construction in the adjacent separate of this guidebook .
Reading: Embeds | discord.js Guide
Some nameSome title Some description here even field title Some value here Some measure here Inline field title Some value here Some value here Inline discipline title Some value here Some rate here Inline field deed Some value here Some value here
# Using the embed constructor
discord.js features the MessageEmbed
exposed in raw window utility class for easy construction and manipulation of embeds .
const { MessageEmbed } = ask ( 'discord.js ' ) ;
const exampleEmbed = new MessageEmbed ( )
. setColor ( ' # 0099ff ' )
. setTitle ( 'Some championship ' )
. setURL ( 'https : //discord.js.org/ ' )
. setAuthor ( { name : 'Some name ', iconURL : 'https : //i.imgur.com/AfFp7pu.png ', url : 'https : //discord.js.org ' } )
. setDescription ( 'Some description here ' )
. setThumbnail ( 'https : //i.imgur.com/AfFp7pu.png ' )
. addFields (
{ name : 'Regular playing field style ', value : 'Some prize here ' } ,
{ name : '\u200B ', measure : '\u200B ' } ,
{ name : 'Inline plain deed ', prize : 'Some respect here ', inline : truthful } ,
{ mention : 'Inline field title ', respect : 'Some respect hera ', inline : true } ,
)
. addField ( 'Inline sphere championship ', 'Some respect here ', true )
. setImage ( 'https : //i.imgur.com/AfFp7pu.png ' )
. setTimestamp ( )
. setFooter ( { textbook : 'Some footer text here ', iconURL : 'https : //i.imgur.com/AfFp7pu.png ' } ) ;
channel. mail ( { embeds : [exampleEmbed ] } ) ;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
tip You do n’t need to include all the elements showcased above. If you want a dim-witted embed, leave some out. The .setColor()
method accepts a ColorResolvable
open in newfangled window, e.g. an integer, HEX color string, an array of RGB values or specific color strings. To add a blank field to the implant, you can use .addField('\u200b', '\u200b')
. The above case chains the manipulating methods to the newly created MessageEmbed aim. If you want to modify the embed based on conditions, you will need to reference it as the changeless exampleEmbed
( for our exercise ) .
const exampleEmbed = newfangled MessageEmbed ( ). setTitle ( 'Some title ' ) ;
if (message .author .bot ) {
exampleEmbed. setColor ( ' # 7289da ' ) ;
}
1
2
3
4
5
# Using an embed object
const exampleEmbed = {
color : 0x0099ff ,
entitle : 'Some title ' ,
url : 'https : //discord.js.org ' ,
generator : {
name : 'Some diagnose ' ,
icon_url : 'https : //i.imgur.com/AfFp7pu.png ' ,
url : 'https : //discord.js.org ' ,
} ,
description : 'Some description hera ' ,
thumbnail : {
url : 'https : //i.imgur.com/AfFp7pu.png ' ,
} ,
fields : [
{
diagnose : 'Regular field entitle ' ,
value : 'Some value here ' ,
} ,
{
name : '\u200b ' ,
value : '\u200b ' ,
inline : false ,
} ,
{
name : 'Inline sphere title ' ,
value : 'Some value here ' ,
inline : true ,
} ,
{
name : 'Inline field title ' ,
value : 'Some value hera ' ,
inline : true ,
} ,
{
name : 'Inline field title ' ,
value : 'Some value here ' ,
inline : true ,
} ,
] ,
trope : {
url : 'https : //i.imgur.com/AfFp7pu.png ' ,
} ,
timestamp : new date ( ) ,
footer : {
textbook : 'Some pedestrian text here ' ,
icon_url : 'https : //i.imgur.com/AfFp7pu.png ' ,
} ,
} ;
channel. air ( { embeds : [exampleEmbed ] } ) ;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
point You do n’t need to include all the elements showcased above. If you want a elementary embed, leave some out. If you want to modify the implant object based on conditions, you will need to reference it directly ( as exampleEmbed
for our case ). You can then ( re ) assign the property values as you would with any other object .
const exampleEmbed = { claim : 'Some title ' } ;
if (message .author .bot ) {
exampleEmbed .color = 0x7289da ;
}
1
2
3
4
5
# Attaching images
You can upload images with your embed message and use them as source for embed fields that support visualize URLs by constructing a MessageAttachment
open in fresh window from them to send as message choice alongside the embed. The attachment parameter takes a BufferResolvable or Stream including the URL to an external persona. You can then reference and use the images inside the embed itself with attachment://fileName.extension
. tip If you plan to attach the same effigy repeatedly, consider hosting it on-line and providing the URL in the respective embed discipline alternatively. This besides makes your bot react faster since it does n’t need to upload the effigy with every reply depending on it .
# Using the MessageEmbed builder
const { MessageAttachment, MessageEmbed } = want ( 'discord.js ' ) ;
const file = new MessageAttachment ( '../assets/discordjs.png ' ) ;
const exampleEmbed = newfangled MessageEmbed ( )
. setTitle ( 'Some title ' )
. setImage ( 'attachment : //discordjs.png ' ) ;
channel. transport ( { embeds : [exampleEmbed ], files : [file ] } ) ;
1
2
3
4
5
6
7
8
# Using an embed object
const { MessageAttachment } = ask ( 'discord.js ' ) ;
const file = modern MessageAttachment ( '../assets/discordjs.png ' ) ;
const exampleEmbed = {
claim : 'Some title ' ,
persona : {
url : 'attachment : //discordjs.png ' ,
} ,
} ;
channel. air ( { embeds : [exampleEmbed ], files : [file ] } ) ;
1
2
3
4
5
6
7
8
9
10
11
12
warning If the images do n’t display inside the embed but outside of it, double-check your syntax to make sure it ‘s as shown above .
# Resending and editing
We will now explain how to edit embedded message capacity and resend a received embed .
# Resending a received embed
To forward a standard implant you retrieve it from the messages embed array ( message.embeds
) and pass it to the MessageEmbed can then be edited before sending it again. warn We measuredly create a newly Embed here rather of just modifying message.embeds[0]
directly to keep the hoard valid. If we were not to do this, the implant in hoard on the original message would diverge from what the actual implant looks like, which can result in unexpected demeanor down the argumentation !
const receivedEmbed = message .embeds [ 0 ] ;
const exampleEmbed = newfangled MessageEmbed (receivedEmbed ). setTitle ( 'New deed ' ) ;
channel. send ( { embeds : [exampleEmbed ] } ) ;
1
2
3
4
# Editing the embedded message content
To edit the contented of an embed you need to pass a new MessageEmbed structure or embed object to the messages .edit()
method .
const exampleEmbed = newfangled MessageEmbed ( )
. setTitle ( 'Some title ' )
. setDescription ( 'Description after the edit ' ) ;
message. edit ( { embeds : [exampleEmbed ] } ) ;
1
2
3
4
5
Read more: Windows Server 2022: A cheat sheet
If you want to build the new embed data on a previously sent implant template, make sure to read the caveats in the previous section .
- To display fields side-by-side, you need at least two consecutive fields set to
inline
- The timestamp will automatically adjust the timezone depending on the user’s device
- Mentions of any kind in embeds will only render correctly within embed descriptions and field values
- Mentions in embeds will not trigger a notification
- Embeds allow masked links (e.g.
[Guide](https://thefartiste.com/ 'optional hovertext')
), but only in description and field values
# Embed limits
There are a few limits to be aware of while planning your embeds due to the API ‘s limitations. here is a quick mention you can come back to :
- Embed titles are limited to 256 characters
- Embed descriptions are limited to 4096 characters
- There can be up to 25 fields
- A field’s name is limited to 256 characters and its value to 1024 characters
- The footer text is limited to 2048 characters
- The author name is limited to 256 characters
- The sum of all characters from all embed structures in a message must not exceed 6000 characters
- Ten embeds can be sent per message
reservoir : Discord API documentationopen in new window