Skip to content

AttachmentBuilder

Defined in: structures/AttachmentBuilder.ts:10

Builder for message attachments, which can be used in several response methods across the library.

new AttachmentBuilder(attachment, data?): AttachmentBuilder

Defined in: structures/AttachmentBuilder.ts:21

Stream | BufferResolvable

The file content — a Buffer, Uint8Array, string path, or readable stream.

AttachmentData = {}

Optional metadata (name, description, content type, reference key).

AttachmentBuilder

get spoiler(): boolean

Defined in: structures/AttachmentBuilder.ts:68

Whether the attachment’s filename is currently marked as a spoiler.

boolean

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.

object

attachments: RESTAPIAttachment[]

files: RawFile[]

const { files, attachments } = builder.resolve();
await interaction.reply({ content: "Here!", files, attachments });
// or even shorter:
await interaction.reply({ content: "Here!", ...builder.resolve() });

setContentType(contentType): this

Defined in: structures/AttachmentBuilder.ts:35

Sets the attachment’s MIME content type.

string

this


setDescription(description): this

Defined in: structures/AttachmentBuilder.ts:30

Sets the attachment’s alt-text description.

string

this


setFile(attachment): this

Defined in: structures/AttachmentBuilder.ts:45

Replaces the attachment’s file content.

Stream | BufferResolvable

this


setKey(key): this

Defined in: structures/AttachmentBuilder.ts:40

Sets a custom reference key for your own use — not sent to Discord.

string

this


setName(name): this

Defined in: structures/AttachmentBuilder.ts:50

Sets the attachment’s filename.

string

this


setSpoiler(spoiler?): this

Defined in: structures/AttachmentBuilder.ts:56

Marks (or unmarks) the attachment as a spoiler by prefixing/stripping SPOILER_ from its filename.

boolean = true

this


toRawFile(): RawFile

Defined in: structures/AttachmentBuilder.ts:73

Produces the multipart file part (files[n])

RawFile


toRestAttachment(index): RESTAPIAttachment

Defined in: structures/AttachmentBuilder.ts:83

Produces the attachments[] entry for the JSON payload

number

RESTAPIAttachment


static from(other): AttachmentBuilder

Defined in: structures/AttachmentBuilder.ts:123

Creates a new AttachmentBuilder from an existing builder or a plain AttachmentPayload object.

AttachmentBuilder | AttachmentPayload

AttachmentBuilder


static resolve(…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.

…AttachmentBuilder[]

object

attachments: RESTAPIAttachment[]

files: RawFile[]

const { files, attachments } = AttachmentBuilder.resolve(builder1, builder2);
await interaction.reply({ content: "Here!", files, attachments });