EmbedBuilder

export declare class EmbedBuilder implements JSONEncodable<APIEmbed>
export declare class EmbedBuilder implements JSONEncodable<APIEmbed>
A builder that creates API-compatible JSON data for embeds.
constructor(data?)
Creates a new embed from API data.
NameTypeOptionalDescription
dataAPIEmbedYes
The API data to create this embed with
Readonly
fields:readonly EmbedFieldBuilder[]
Gets the fields of this embed.
addFields(...fields):this
Appends fields to the embed.
Remarks
This method accepts either an array of fields or a variable number of field parameters. The maximum amount of fields that can be added is 25.
Example
Using an array:
const fields: APIEmbedField[] = ...;
const embed = new EmbedBuilder()
.addFields(fields);
const fields: APIEmbedField[] = ...;
const embed = new EmbedBuilder()
.addFields(fields);
Example
Using rest parameters (variadic):
const embed = new EmbedBuilder()
.addFields(
{ name: 'Field 1', value: 'Value 1' },
{ name: 'Field 2', value: 'Value 2' },
);
const embed = new EmbedBuilder()
.addFields(
{ name: 'Field 1', value: 'Value 1' },
{ name: 'Field 2', value: 'Value 2' },
);
NameTypeOptionalDescription
...fieldsRestOrArray<APIEmbedField | EmbedFieldBuilder | ((builder: EmbedFieldBuilder) => EmbedFieldBuilder)>No
The fields to add
clearAuthor():this
Clears the author of this embed.
clearColor():this
Clears the color of this embed.
clearDescription():this
Clears the description of this embed.
clearFooter():this
Clears the footer of this embed.
clearImage():this
Clears the image of this embed.
clearThumbnail():this
Clears the thumbnail of this embed.
clearTimestamp():this
Clears the timestamp of this embed.
clearTitle():this
Clears the title of this embed.
clearURL():this
Clears the URL of this embed.
setAuthor(options):this
Sets the author of this embed.
NameTypeOptionalDescription
optionsAPIEmbedAuthor | EmbedAuthorBuilder | ((builder: EmbedAuthorBuilder) => EmbedAuthorBuilder)No
The options to use
setColor(color):this
Sets the color of this embed.
NameTypeOptionalDescription
colornumberNo
The color to use
setDescription(description):this
Sets the description of this embed.
NameTypeOptionalDescription
descriptionstringNo
The description to use
setFields(...fields):this
Sets the fields for this embed.
Remarks
This method is an alias for spliceFields. More specifically, it splices the entire array of fields, replacing them with the provided fields.
You can set a maximum of 25 fields.
NameTypeOptionalDescription
...fieldsRestOrArray<APIEmbedField | EmbedFieldBuilder | ((builder: EmbedFieldBuilder) => EmbedFieldBuilder)>No
The fields to set
setFooter(options):this
Sets the footer of this embed.
NameTypeOptionalDescription
optionsAPIEmbedFooter | EmbedFooterBuilder | ((builder: EmbedFooterBuilder) => EmbedFooterBuilder)No
The footer to use
setImage(url):this
Sets the image of this embed.
NameTypeOptionalDescription
urlstringNo
The image URL to use
setThumbnail(url):this
Sets the thumbnail of this embed.
NameTypeOptionalDescription
urlstringNo
The thumbnail URL to use
setTimestamp(timestamp?):this
Sets the timestamp of this embed.
NameTypeOptionalDescription
timestampDate | number | stringYes
The timestamp or date to use
setTitle(title):this
Sets the title for this embed.
NameTypeOptionalDescription
titlestringNo
The title to use
setURL(url):this
Sets the URL of this embed.
NameTypeOptionalDescription
urlstringNo
The URL to use
spliceFields(index, deleteCount, ...fields):this
Removes, replaces, or inserts fields for this embed.
Remarks
This method behaves similarly to Array.prototype.splice(). The maximum amount of fields that can be added is 25.
It's useful for modifying and adjusting order of the already-existing fields of an embed.
Example
Remove the first field:
embed.spliceFields(0, 1);
embed.spliceFields(0, 1);
Example
Remove the first n fields:
const n = 4;
embed.spliceFields(0, n);
const n = 4;
embed.spliceFields(0, n);
Example
Remove the last field:
embed.spliceFields(-1, 1);
embed.spliceFields(-1, 1);
NameTypeOptionalDescription
indexnumberNo
The index to start at
deleteCountnumberNo
The number of fields to remove
...fields(APIEmbedField | EmbedFieldBuilder | ((builder: EmbedFieldBuilder) => EmbedFieldBuilder))[]No
The replacing field objects
toJSON(validationOverride?):APIEmbed
Serializes this builder to API-compatible JSON data.
Note that by disabling validation, there is no guarantee that the resulting object will be valid.
NameTypeOptionalDescription
validationOverridebooleanYes
Force validation to run/not run regardless of your global preference
updateAuthor(updater):this
Updates the author of this embed (and creates it if it doesn't exist).
NameTypeOptionalDescription
updater(builder: EmbedAuthorBuilder) => voidNo
The function to update the author with
updateFooter(updater):this
Updates the footer of this embed (and creates it if it doesn't exist).
NameTypeOptionalDescription
updater(builder: EmbedFooterBuilder) => voidNo
The function to update the footer with