File Attachments
Upload files with AttachmentBuilder or plain { name, data } / { name, url }.
Attach files on reply, send, or channel.send. Prefer AttachmentBuilder when you have a buffer or URL and a filename.
AttachmentBuilder (recommended)
javascript
import { AttachmentBuilder, Client, Events } from '@fluxerjs/core';
const client = new Client();
client.on(Events.MessageCreate, async (message) => {
if (message.content !== '!file') return;
await message.reply({
content: 'Here is a file:',
files: [new AttachmentBuilder(Buffer.from('Hello from Fluxer!', 'utf-8'), { name: 'hello.txt' })],
});
});URL form:
javascript
await message.reply({
content: 'Image from URL:',
files: [new AttachmentBuilder('https://example.com/a.png', { name: 'a.png' })],
});Optional description and spoiler: true live on the builder options. Plain { name, data } / { name, url } objects still work. See Builders and Attachments by URL.
Metadata and flags
When you need titles, descriptions, or flags beyond the builder, pass an attachments array. The id matches the file index (0, 1, …).
javascript
import { AttachmentBuilder, MessageAttachmentFlags } from '@fluxerjs/core';
await message.reply({
content: 'Spoiler image:',
files: [new AttachmentBuilder(imageBuffer, { name: 'secret.png', spoiler: true })],
attachments: [
{
id: 0,
filename: 'SPOILER_secret.png',
title: 'Hidden image',
flags: MessageAttachmentFlags.IS_SPOILER,
},
],
});Useful flags:
javascript
MessageAttachmentFlags.IS_SPOILER // blur until clicked
MessageAttachmentFlags.CONTAINS_EXPLICIT_MEDIA
MessageAttachmentFlags.IS_ANIMATED // GIF / animated WebP
// Combine with |
flags: MessageAttachmentFlags.IS_SPOILER | MessageAttachmentFlags.IS_ANIMATEDFrom disk
javascript
import { readFileSync } from 'node:fs';
import { AttachmentBuilder } from '@fluxerjs/core';
const data = readFileSync('./chart.png');
await message.reply({
files: [new AttachmentBuilder(data, { name: 'chart.png' })],
});Try !attachurl in ping-bot or attachments-bot for runnable demos.