AttachmentBuilder
AttachmentBuilder wraps raw binary data into a named attachment object for use in message sends.
Import
Section titled “Import”import { AttachmentBuilder } from "lunibee";import { AttachmentBuilder } from "lunibee";Constructor
Section titled “Constructor”new AttachmentBuilder(data: Uint8Array | ArrayBuffer | Buffer, options?: AttachmentData)new AttachmentBuilder(data: Uint8Array | ArrayBuffer | Buffer, options?: AttachmentData)| Parameter | Type | Description |
|---|---|---|
data |
Uint8Array | ArrayBuffer | Buffer |
Raw file data. |
options.name |
string |
Filename including extension (e.g. "image.png"). |
options.description |
string |
Alt text description for the file. |
Methods
Section titled “Methods”setName(name)
Section titled “setName(name)”Sets or changes the filename.
attachment.setName("welcome-banner.png");attachment.setName("welcome-banner.png");setDescription(description)
Section titled “setDescription(description)”Sets the alt text for the file.
attachment.setDescription("A welcome banner for new members.");attachment.setDescription("A welcome banner for new members.");toJSON()
Section titled “toJSON()”Serializes to a REST-ready attachment object.
Examples
Section titled “Examples”Send a generated image
import { AttachmentBuilder } from "lunibee";import { readFile } from "node:fs/promises";
const imageData = await readFile("./assets/welcome.png");const attachment = new AttachmentBuilder(imageData, { name: "welcome.png", description: "Welcome banner",});
await channel.send({ files: [attachment] });import { AttachmentBuilder } from "lunibee";import { readFile } from "node:fs/promises";
const imageData = await readFile("./assets/welcome.png");const attachment = new AttachmentBuilder(imageData, { name: "welcome.png", description: "Welcome banner",});
await channel.send({ files: [attachment] });Send with an embed referencing the attachment
const attachment = new AttachmentBuilder(imageData, { name: "chart.png" });const embed = new EmbedBuilder() .setTitle("Monthly Stats") .setImage("attachment://chart.png"); // reference the attachment by name
await channel.send({ embeds: [embed], files: [attachment] });const attachment = new AttachmentBuilder(imageData, { name: "chart.png" });const embed = new EmbedBuilder() .setTitle("Monthly Stats") .setImage("attachment://chart.png"); // reference the attachment by name
await channel.send({ embeds: [embed], files: [attachment] });