class MessageBuilder

external
declare class MessageBuilder implements JSONEncodable<RESTPostAPIChannelMessageJSONBody>

A builder that creates API-compatible JSON data for messages.

Constructors

Creates a new message builder from API data.

readonlyexternal
attachments : readonly AttachmentBuilder[]

Gets the attachments of this message.

readonlyexternal
components : readonly MessageTopLevelComponentBuilder[]

Gets the components of this message.

readonlyexternal
embeds : readonly EmbedBuilder[]

Gets the embeds of this message.

external
addActionRowComponents() : this

Adds action row components to this message.

external
addAttachments() : this

Adds attachments to this message.

external
addContainerComponents() : this

Adds container components to this message.

external
addEmbeds() : this

Appends embeds to this message.

Examples:Using an array:
const embeds: APIEmbed[] = ...;
const message = new MessageBuilder()
	.addEmbeds(embeds);
Using rest parameters (variadic):
const message = new MessageBuilder()
	.addEmbeds(
		{ title: 'Embed 1' },
		{ title: 'Embed 2' },
	);

external
addFileComponents(
...components: RestOrArray<APIFileComponent | FileBuilder | ((builder: FileBuilder) => FileBuilder)>
) : this

Adds file components to this message.

external
addMediaGalleryComponents() : this

Adds media gallery components to this message.

external
addSectionComponents() : this

Adds section components to this message.

external
addSeparatorComponents() : this

Adds separator components to this message.

external
addStickerIds(
...stickerIds: RestOrArray<Snowflake>
) : this

Adds sticker ids to this message.

external
addTextDisplayComponents() : this

Adds text display components to this message.

external
clearAllowedMentions() : this

Clears the allowed mentions for this message.

external
clearContent() : this

Clears the content of the message.

external
clearFlags() : this

Clears the flags for this message.

external
clearMessageReference() : this

Clears the message reference for this message.

external
clearNonce() : this

Clears the nonce of the message.

external
clearPoll() : this

Clears the poll for this message.

external
setAllowedMentions() : this

Sets the allowed mentions for this message.

external
setAttachments() : this

Sets attachments for this message.

external
setContent(
content: string
) : this

Sets the content of the message.

external
setEmbeds() : this

Sets the embeds for this message.

external
setEnforceNonce(
enforceNonce?: boolean
) : this

Sets whether to enforce recent uniqueness of the nonce of this message.

external
setFlags() : this

Sets the flags for this message.

external
setMessageReference() : this

Sets the message reference for this message.

external
setNonce(
nonce: number | string
) : this

Sets the nonce of the message.

external
setPoll(
poll: APIPoll | PollBuilder | ((builder: PollBuilder) => PollBuilder)
) : this

Sets the poll for this message.

external
setStickerIds(
...stickerIds: RestOrArray<Snowflake>
) : this

Sets the sticker ids of this message.

external
setTTS(
tts?: boolean
) : this

Sets whether the message is TTS.

external
spliceAttachments(
start: number
deleteCount: number
) : this

Removes, replaces, or inserts attachments for this message.

Examples:Remove the first attachment:
message.spliceAttachments(0, 1);
Remove the first n attachments:
const n = 4;
message.spliceAttachments(0, n);
Remove the last attachment:
message.spliceAttachments(-1, 1);

external
spliceComponents() : this

Removes, replaces, or inserts components for this message.

Examples:Remove the first component:
message.spliceComponents(0, 1);
Remove the first n components:
const n = 4;
message.spliceComponents(0, n);
Remove the last component:
message.spliceComponents(-1, 1);

external
spliceEmbeds(
start: number
deleteCount: number
) : this

Removes, replaces, or inserts embeds for this message.

Examples:Remove the first embed:
message.spliceEmbeds(0, 1);
Remove the first n embeds:
const n = 4;
message.spliceEmbeds(0, n);
Remove the last embed:
message.spliceEmbeds(-1, 1);

external
spliceStickerIds(
index: number
deleteCount: number
...stickerIds: RestOrArray<Snowflake>
) : this

Removes, replaces, or inserts sticker ids for this message.

Examples:Remove the first sticker id:
message.spliceStickerIds(0, 1);
Remove the first n sticker ids:
const n = 4;
message.spliceStickerIds(0, n);
Remove the last sticker id:
message.spliceStickerIds(-1, 1);

external
toJSON(
validationOverride?: boolean
) : 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.

external
updateAllowedMentions(
updater: (builder: AllowedMentionsBuilder) => void
) : this

Updates the allowed mentions for this message (and creates it if it doesn't exist)

external
updateMessageReference(
updater: (builder: MessageReferenceBuilder) => void
) : this

Updates the message reference for this message (and creates it if it doesn't exist)

external
updatePoll(
updater: (builder: PollBuilder) => void
) : this

Updates the poll for this message (and creates it if it doesn't exist)