Recipes
Embeds, Formatting & Attachments
Embed Builder
The Embed builder allows you to create rich embedded messages with titles, descriptions, fields, images, and more.
import { , , , type } from 'seyfert';
@({
: 'embed',
: 'Send a rich embed',
})
export default class extends {
async (: ) {
const = new ()
.('Server Info')
.('Here is some information about this server.')
.(0x5865F2)
.({ : .. })
.({ : 'Powered by Seyfert' })
.(
{ : 'Members', : '1,234', : true },
{ : 'Channels', : '42', : true },
{ : 'Created', : '<t:1609459200:R>', : true },
)
.('https://example.com/banner.png')
.()
.('https://discord.gg/example');
await .({ : [] });
}
}You can also pass a partial embed object to the constructor, which is useful for i18n:
const embed = new Embed(ctx.t.commands.help.embed.get())
.setColor('Blurple');Color Options
The setColor method accepts a numeric hex value or a named color string:
new ().(0xFF0000); // Hex value
new ().('Blue'); // Named color
new ().('Blurple'); // Discord's brand colorFormatter Utilities
Seyfert provides a Formatter class with static methods for Discord markdown formatting:
import { } from 'seyfert';
import { } from 'seyfert/lib/common';
// Text formatting
.('text'); // **text**
.('text'); // *text*
.('text'); // __text__
.('text'); // ~~text~~
.('text'); // `text`
.('ts', 'const x = 1'); // ```ts\nconst x = 1\n```
.('text'); // ||text||
.('text'); // > text
.('text'); // >>> text
.('Click here', 'https://example.com'); // [Click here](https://example.com)Mentions
.('userId'); // <@userId>
.('channelId'); // <#channelId>
.('roleId'); // <@&roleId>Timestamps
Discord renders timestamps in the user's local timezone:
const = new ();
.(, .); // "2 hours ago"
.(, .); // "April 20, 2021 at 16:20"
.(, .); // "April 20, 2021"
.(, .); // "16:20"Practical Example
import { , , , , type } from 'seyfert';
import { } from 'seyfert/lib/common';
@({
: 'userinfo',
: 'Get user information',
})
export default class extends {
async (: ) {
const = .;
const = new ()
.(.(.))
.(
[
`${.('ID:')} ${.(.)}`,
`${.('Created:')} ${.(new (), .)}`,
].('\n')
)
.(0x5865F2);
await .({ : [] });
}
}Attachment Builder
Create file attachments from buffers or URLs:
import { , , , type } from 'seyfert';
@({
: 'attach',
: 'Send a file attachment',
})
export default class extends {
async (: ) {
const = .('Hello, World!');
const = new ()
.('hello.txt')
.('buffer', );
await .({
: 'Here is the file:',
: [],
});
}
}From a URL
const = new ()
.('url', 'https://example.com/image.png')
.('downloaded.png');Referencing in Embeds
You can reference an attachment within an embed using the attachment:// protocol:
const = new ()
.('chart.png')
.('buffer', );
const = new ()
.('Statistics')
.('attachment://chart.png');Sending Components with Messages
For a complete guide on building and handling interactive components (buttons, select menus, modals), see the Components guide.
Quick Reference
// With embeds
await .write({ : [], : [] });
// Ephemeral message (only visible to the user)
await .write({
: 'Only you can see this',
: .,
});
// Disable buttons after use
await .editOrReply({
: [
new <>().(
new ()
.('done')
.('Done')
.(.)
.(true),
),
],
});
// Remove all components
await .editOrReply({ : [] });