AttachmentBuilder
Class: AttachmentBuilder
Section titled “Class: AttachmentBuilder”Defined in: structures/AttachmentBuilder.ts:10
Builder for message attachments, which can be used in several response methods across the library.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AttachmentBuilder(
attachment,data?):AttachmentBuilder
Defined in: structures/AttachmentBuilder.ts:21
Parameters
Section titled “Parameters”attachment
Section titled “attachment”Stream | BufferResolvable
The file content — a Buffer, Uint8Array, string path, or readable stream.
AttachmentData = {}
Optional metadata (name, description, content type, reference key).
Returns
Section titled “Returns”AttachmentBuilder
Accessors
Section titled “Accessors”spoiler
Section titled “spoiler”Get Signature
Section titled “Get Signature”get spoiler():
boolean
Defined in: structures/AttachmentBuilder.ts:68
Whether the attachment’s filename is currently marked as a spoiler.
Returns
Section titled “Returns”boolean
Methods
Section titled “Methods”resolve()
Section titled “resolve()”resolve():
object
Defined in: structures/AttachmentBuilder.ts:100
Resolves this builder into the parallel files and attachments arrays ready to spread into your API call options.
Returns
Section titled “Returns”object
attachments
Section titled “attachments”attachments:
RESTAPIAttachment[]
files:
RawFile[]
Example
Section titled “Example”const { files, attachments } = builder.resolve();await interaction.reply({ content: "Here!", files, attachments });// or even shorter:await interaction.reply({ content: "Here!", ...builder.resolve() });setContentType()
Section titled “setContentType()”setContentType(
contentType):this
Defined in: structures/AttachmentBuilder.ts:35
Sets the attachment’s MIME content type.
Parameters
Section titled “Parameters”contentType
Section titled “contentType”string
Returns
Section titled “Returns”this
setDescription()
Section titled “setDescription()”setDescription(
description):this
Defined in: structures/AttachmentBuilder.ts:30
Sets the attachment’s alt-text description.
Parameters
Section titled “Parameters”description
Section titled “description”string
Returns
Section titled “Returns”this
setFile()
Section titled “setFile()”setFile(
attachment):this
Defined in: structures/AttachmentBuilder.ts:45
Replaces the attachment’s file content.
Parameters
Section titled “Parameters”attachment
Section titled “attachment”Stream | BufferResolvable
Returns
Section titled “Returns”this
setKey()
Section titled “setKey()”setKey(
key):this
Defined in: structures/AttachmentBuilder.ts:40
Sets a custom reference key for your own use — not sent to Discord.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”this
setName()
Section titled “setName()”setName(
name):this
Defined in: structures/AttachmentBuilder.ts:50
Sets the attachment’s filename.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”this
setSpoiler()
Section titled “setSpoiler()”setSpoiler(
spoiler?):this
Defined in: structures/AttachmentBuilder.ts:56
Marks (or unmarks) the attachment as a spoiler by prefixing/stripping SPOILER_ from its filename.
Parameters
Section titled “Parameters”spoiler?
Section titled “spoiler?”boolean = true
Returns
Section titled “Returns”this
toRawFile()
Section titled “toRawFile()”toRawFile():
RawFile
Defined in: structures/AttachmentBuilder.ts:73
Produces the multipart file part (files[n])
Returns
Section titled “Returns”toRestAttachment()
Section titled “toRestAttachment()”toRestAttachment(
index):RESTAPIAttachment
Defined in: structures/AttachmentBuilder.ts:83
Produces the attachments[] entry for the JSON payload
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”RESTAPIAttachment
from()
Section titled “from()”
staticfrom(other):AttachmentBuilder
Defined in: structures/AttachmentBuilder.ts:123
Creates a new AttachmentBuilder from an existing builder or a plain AttachmentPayload object.
Parameters
Section titled “Parameters”AttachmentBuilder | AttachmentPayload
Returns
Section titled “Returns”AttachmentBuilder
resolve()
Section titled “resolve()”
staticresolve(…builders):object
Defined in: structures/AttachmentBuilder.ts:112
Resolves an array of AttachmentBuilders into parallel files and
attachments arrays ready to spread into your API call options.
Parameters
Section titled “Parameters”builders
Section titled “builders”…AttachmentBuilder[]
Returns
Section titled “Returns”object
attachments
Section titled “attachments”attachments:
RESTAPIAttachment[]
files:
RawFile[]
Example
Section titled “Example”const { files, attachments } = AttachmentBuilder.resolve(builder1, builder2);await interaction.reply({ content: "Here!", files, attachments });