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>YesThe 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)>NoThe action row components to add
addAttachments(...attachments):this
Adds attachments to this message.
NameTypeOptionalDescription
...attachmentsRestOrArray<APIAttachment | AttachmentBuilder | ((builder: AttachmentBuilder) => AttachmentBuilder)>NoThe attachments to add
addContainerComponents(...components):this
Adds container components to this message.
NameTypeOptionalDescription
...componentsRestOrArray<APIContainerComponent | ContainerBuilder | ((builder: ContainerBuilder) => ContainerBuilder)>NoThe 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)>NoThe embeds to add
addFileComponents(...components):this
Adds file components to this message.
NameTypeOptionalDescription
...componentsRestOrArray<APIFileComponent | FileBuilder | ((builder: FileBuilder) => FileBuilder)>NoThe file components to add
addMediaGalleryComponents(...components):this
Adds media gallery components to this message.
NameTypeOptionalDescription
...componentsRestOrArray<APIMediaGalleryComponent | MediaGalleryBuilder | ((builder: MediaGalleryBuilder) => MediaGalleryBuilder)>NoThe media gallery components to add
addSectionComponents(...components):this
Adds section components to this message.
NameTypeOptionalDescription
...componentsRestOrArray<APISectionComponent | SectionBuilder | ((builder: SectionBuilder) => SectionBuilder)>NoThe section components to add
addSeparatorComponents(...components):this
Adds separator components to this message.
NameTypeOptionalDescription
...componentsRestOrArray<APISeparatorComponent | SeparatorBuilder | ((builder: SeparatorBuilder) => SeparatorBuilder)>NoThe separator components to add
addStickerIds(...stickerIds):this
Adds sticker ids to this message.
NameTypeOptionalDescription
...stickerIdsRestOrArray<Snowflake>NoThe ids of the stickers to add
addTextDisplayComponents(...components):this
Adds text display components to this message.
NameTypeOptionalDescription
...componentsRestOrArray<APITextDisplayComponent | TextDisplayBuilder | ((builder: TextDisplayBuilder) => TextDisplayBuilder)>NoThe 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)NoThe allowed mentions to set
setAttachments(...attachments):this
Sets attachments for this message.
NameTypeOptionalDescription
...attachmentsRestOrArray<APIAttachment | AttachmentBuilder | ((builder: AttachmentBuilder) => AttachmentBuilder)>NoThe attachments to set
setContent(content):this
Sets the content of the message.
NameTypeOptionalDescription
contentstringNoThe content to set
setEmbeds(...embeds):this
Sets the embeds for this message.
NameTypeOptionalDescription
...embedsRestOrArray<APIEmbed | EmbedBuilder | ((builder: EmbedBuilder) => EmbedBuilder)>NoThe embeds to set
setEnforceNonce(enforceNonce?):this
Sets whether to enforce recent uniqueness of the nonce of this message.
NameTypeOptionalDescription
enforceNoncebooleanYesWhether to enforce recent uniqueness of the nonce of this message
setFlags(flags):this
Sets the flags for this message.
NameTypeOptionalDescription
flagsMessageFlagsNoThe flags to set
setMessageReference(reference):this
Sets the message reference for this message.
NameTypeOptionalDescription
referenceAPIMessageReference | MessageReferenceBuilder | ((builder: MessageReferenceBuilder) => MessageReferenceBuilder)NoThe reference to set
setNonce(nonce):this
Sets the nonce of the message.
NameTypeOptionalDescription
noncenumber | stringNoThe nonce to set
setPoll(poll):this
Sets the poll for this message.
NameTypeOptionalDescription
pollAPIPoll | PollBuilder | ((builder: PollBuilder) => PollBuilder)NoThe poll to set
setStickerIds(...stickerIds):this
Sets the sticker ids of this message.
NameTypeOptionalDescription
...stickerIdsRestOrArray<Snowflake>NoThe ids of the stickers to set
setTTS(tts?):this
Sets whether the message is TTS.
NameTypeOptionalDescription
ttsbooleanYesWhether 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
startnumberNoThe index to start at
deleteCountnumberNoThe amount of attachments to remove
...attachmentsRestOrArray<APIAttachment | AttachmentBuilder | ((builder: AttachmentBuilder) => AttachmentBuilder)>NoThe 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
startnumberNoThe index to start at
deleteCountnumberNoThe amount of components to remove
...componentsRestOrArray<APIMessageTopLevelComponent | MessageTopLevelComponentBuilder>NoThe 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
startnumberNoThe index to start at
deleteCountnumberNoThe amount of embeds to remove
...embedsRestOrArray<APIEmbed | EmbedBuilder | ((builder: EmbedBuilder) => EmbedBuilder)>NoThe 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
indexnumberNoThe index to start at
deleteCountnumberNoThe amount of sticker ids to remove
...stickerIdsRestOrArray<Snowflake>NoThe 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
validationOverridebooleanYesForce 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) => voidNoThe 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) => voidNoThe 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) => voidNoThe function to update the poll with