MessageBuilder

export declare class MessageBuilder implements JSONEncodable<RESTPostAPIChannelMessageJSONBody>
export declare class MessageBuilder implements JSONEncodable<RESTPostAPIChannelMessageJSONBody>
A builder that creates API-compatible JSON data for messages.
constructor(data?)
Creates a new message builder from API data.
NameTypeOptionalDescription
dataPartial<RESTPostAPIChannelMessageJSONBody>Yes
The API data to create this message builder with
Readonly
attachments:readonly AttachmentBuilder[]
Gets the attachments of this message.
Readonly
components:readonly MessageTopLevelComponentBuilder[]
Gets the components of this message.
Readonly
embeds:readonly EmbedBuilder[]
Gets the embeds of this message.
addActionRowComponents(...components):this
Adds action row components to this message.
NameTypeOptionalDescription
...componentsRestOrArray<ActionRowBuilder | APIActionRowComponent<APIComponentInMessageActionRow> | ((builder: ActionRowBuilder) => ActionRowBuilder)>No
The action row components to add
addAttachments(...attachments):this
Adds attachments to this message.
NameTypeOptionalDescription
...attachmentsRestOrArray<APIAttachment | AttachmentBuilder | ((builder: AttachmentBuilder) => AttachmentBuilder)>No
The attachments to add
addContainerComponents(...components):this
Adds container components to this message.
NameTypeOptionalDescription
...componentsRestOrArray<APIContainerComponent | ContainerBuilder | ((builder: ContainerBuilder) => ContainerBuilder)>No
The container components to add
addEmbeds(...embeds):this
Appends embeds to this message.
Remarks
The maximum amount of embeds that can be added is 10.
Example
Using an array:
const embeds: APIEmbed[] = ...;
const message = new MessageBuilder()
.addEmbeds(embeds);
const embeds: APIEmbed[] = ...;
const message = new MessageBuilder()
.addEmbeds(embeds);
Example
Using rest parameters (variadic):
const message = new MessageBuilder()
.addEmbeds(
{ title: 'Embed 1' },
{ title: 'Embed 2' },
);
const message = new MessageBuilder()
.addEmbeds(
{ title: 'Embed 1' },
{ title: 'Embed 2' },
);
NameTypeOptionalDescription
...embedsRestOrArray<APIEmbed | EmbedBuilder | ((builder: EmbedBuilder) => EmbedBuilder)>No
The embeds to add
addFileComponents(...components):this
Adds file components to this message.
NameTypeOptionalDescription
...componentsRestOrArray<APIFileComponent | FileBuilder | ((builder: FileBuilder) => FileBuilder)>No
The file components to add
addMediaGalleryComponents(...components):this
Adds media gallery components to this message.
NameTypeOptionalDescription
...componentsRestOrArray<APIMediaGalleryComponent | MediaGalleryBuilder | ((builder: MediaGalleryBuilder) => MediaGalleryBuilder)>No
The media gallery components to add
addSectionComponents(...components):this
Adds section components to this message.
NameTypeOptionalDescription
...componentsRestOrArray<APISectionComponent | SectionBuilder | ((builder: SectionBuilder) => SectionBuilder)>No
The section components to add
addSeparatorComponents(...components):this
Adds separator components to this message.
NameTypeOptionalDescription
...componentsRestOrArray<APISeparatorComponent | SeparatorBuilder | ((builder: SeparatorBuilder) => SeparatorBuilder)>No
The separator components to add
addStickerIds(...stickerIds):this
Adds sticker ids to this message.
NameTypeOptionalDescription
...stickerIdsRestOrArray<Snowflake>No
The ids of the stickers to add
addTextDisplayComponents(...components):this
Adds text display components to this message.
NameTypeOptionalDescription
...componentsRestOrArray<APITextDisplayComponent | TextDisplayBuilder | ((builder: TextDisplayBuilder) => TextDisplayBuilder)>No
The text display components to add
clearAllowedMentions():this
Clears the allowed mentions for this message.
clearContent():this
Clears the content of the message.
clearFlags():this
Clears the flags for this message.
clearMessageReference():this
Clears the message reference for this message.
clearNonce():this
Clears the nonce of the message.
clearPoll():this
Clears the poll for this message.
setAllowedMentions(allowedMentions):this
Sets the allowed mentions for this message.
NameTypeOptionalDescription
allowedMentionsAllowedMentionsBuilder | APIAllowedMentions | ((builder: AllowedMentionsBuilder) => AllowedMentionsBuilder)No
The allowed mentions to set
setAttachments(...attachments):this
Sets attachments for this message.
NameTypeOptionalDescription
...attachmentsRestOrArray<APIAttachment | AttachmentBuilder | ((builder: AttachmentBuilder) => AttachmentBuilder)>No
The attachments to set
setContent(content):this
Sets the content of the message.
NameTypeOptionalDescription
contentstringNo
The content to set
setEmbeds(...embeds):this
Sets the embeds for this message.
NameTypeOptionalDescription
...embedsRestOrArray<APIEmbed | EmbedBuilder | ((builder: EmbedBuilder) => EmbedBuilder)>No
The embeds to set
setEnforceNonce(enforceNonce?):this
Sets whether to enforce recent uniqueness of the nonce of this message.
NameTypeOptionalDescription
enforceNoncebooleanYes
Whether to enforce recent uniqueness of the nonce of this message
setFlags(flags):this
Sets the flags for this message.
NameTypeOptionalDescription
flagsMessageFlagsNo
The flags to set
setMessageReference(reference):this
Sets the message reference for this message.
NameTypeOptionalDescription
referenceAPIMessageReference | MessageReferenceBuilder | ((builder: MessageReferenceBuilder) => MessageReferenceBuilder)No
The reference to set
setNonce(nonce):this
Sets the nonce of the message.
NameTypeOptionalDescription
noncenumber | stringNo
The nonce to set
setPoll(poll):this
Sets the poll for this message.
NameTypeOptionalDescription
pollAPIPoll | PollBuilder | ((builder: PollBuilder) => PollBuilder)No
The poll to set
setStickerIds(...stickerIds):this
Sets the sticker ids of this message.
NameTypeOptionalDescription
...stickerIdsRestOrArray<Snowflake>No
The ids of the stickers to set
setTTS(tts?):this
Sets whether the message is TTS.
NameTypeOptionalDescription
ttsbooleanYes
Whether the message is TTS
spliceAttachments(start, deleteCount, ...attachments):this
Removes, replaces, or inserts attachments for this message.
Remarks
This method behaves similarly to Array.prototype.splice().
It's useful for modifying and adjusting order of the already-existing attachments of a message.
Example
Remove the first attachment:
message.spliceAttachments(0, 1);
message.spliceAttachments(0, 1);
Example
Remove the first n attachments:
const n = 4;
message.spliceAttachments(0, n);
const n = 4;
message.spliceAttachments(0, n);
Example
Remove the last attachment:
message.spliceAttachments(-1, 1);
message.spliceAttachments(-1, 1);
NameTypeOptionalDescription
startnumberNo
The index to start at
deleteCountnumberNo
The amount of attachments to remove
...attachmentsRestOrArray<APIAttachment | AttachmentBuilder | ((builder: AttachmentBuilder) => AttachmentBuilder)>No
The attachments to insert
spliceComponents(start, deleteCount, ...components):this
Removes, replaces, or inserts components for this message.
Remarks
This method behaves similarly to Array.prototype.splice().
It's useful for modifying and adjusting order of the already-existing components of a message.
Example
Remove the first component:
message.spliceComponents(0, 1);
message.spliceComponents(0, 1);
Example
Remove the first n components:
const n = 4;
message.spliceComponents(0, n);
const n = 4;
message.spliceComponents(0, n);
Example
Remove the last component:
message.spliceComponents(-1, 1);
message.spliceComponents(-1, 1);
NameTypeOptionalDescription
startnumberNo
The index to start at
deleteCountnumberNo
The amount of components to remove
...componentsRestOrArray<APIMessageTopLevelComponent | MessageTopLevelComponentBuilder>No
The components to insert
spliceEmbeds(start, deleteCount, ...embeds):this
Removes, replaces, or inserts embeds for this message.
Remarks
This method behaves similarly to Array.prototype.splice().
It's useful for modifying and adjusting order of the already-existing embeds of a message.
Example
Remove the first embed:
message.spliceEmbeds(0, 1);
message.spliceEmbeds(0, 1);
Example
Remove the first n embeds:
const n = 4;
message.spliceEmbeds(0, n);
const n = 4;
message.spliceEmbeds(0, n);
Example
Remove the last embed:
message.spliceEmbeds(-1, 1);
message.spliceEmbeds(-1, 1);
NameTypeOptionalDescription
startnumberNo
The index to start at
deleteCountnumberNo
The amount of embeds to remove
...embedsRestOrArray<APIEmbed | EmbedBuilder | ((builder: EmbedBuilder) => EmbedBuilder)>No
The embeds to insert
spliceStickerIds(index, deleteCount, ...stickerIds):this
Removes, replaces, or inserts sticker ids for this message.
Remarks
This method behaves similarly to Array.prototype.splice().
It's useful for modifying and adjusting order of the already-existing sticker ids of a message.
Example
Remove the first sticker id:
message.spliceStickerIds(0, 1);
message.spliceStickerIds(0, 1);
Example
Remove the first n sticker ids:
const n = 4;
message.spliceStickerIds(0, n);
const n = 4;
message.spliceStickerIds(0, n);
Example
Remove the last sticker id:
message.spliceStickerIds(-1, 1);
message.spliceStickerIds(-1, 1);
NameTypeOptionalDescription
indexnumberNo
The index to start at
deleteCountnumberNo
The amount of sticker ids to remove
...stickerIdsRestOrArray<Snowflake>No
The sticker ids to insert
toJSON(validationOverride?):RESTPostAPIChannelMessageJSONBody
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
updateAllowedMentions(updater):this
Updates the allowed mentions for this message (and creates it if it doesn't exist)
NameTypeOptionalDescription
updater(builder: AllowedMentionsBuilder) => voidNo
The function to update the allowed mentions with
updateMessageReference(updater):this
Updates the message reference for this message (and creates it if it doesn't exist)
NameTypeOptionalDescription
updater(builder: MessageReferenceBuilder) => voidNo
The function to update the message reference with
updatePoll(updater):this
Updates the poll for this message (and creates it if it doesn't exist)
NameTypeOptionalDescription
updater(builder: PollBuilder) => voidNo
The function to update the poll with