Skip to content

AttachmentBuilder

AttachmentBuilder wraps raw binary data into a named attachment object for use in message sends.

import { AttachmentBuilder } from "lunibee";
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.

Sets or changes the filename.

attachment.setName("welcome-banner.png");

Sets the alt text for the file.

attachment.setDescription("A welcome banner for new members.");

Serializes to a REST-ready attachment object.

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] });

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] });