Skip to content

Buttons, selects and layouts

Only bots may send components, and pictures and files are attachments of the same message, never URLs: clients never load anything remote to show a component.

Up to 5 action rows; each holds up to 5 buttons or one select.

import { ActionRowBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuBuilder } from '@zaun/bot';
interaction.reply({
content: 'Pick one',
components: [
new ActionRowBuilder().addComponents(
new ButtonBuilder().setCustomId('a').setLabel('Option A').setStyle(ButtonStyle.Primary),
new ButtonBuilder().setCustomId('b').setLabel('Option B').setStyle(ButtonStyle.Secondary),
new ButtonBuilder().setURL('https://zaun.example/help').setLabel('Help'),
),
new ActionRowBuilder().addComponents(
new StringSelectMenuBuilder().setCustomId('colour').setPlaceholder('Colour')
.addOptions({ label: 'Red', value: 'red' }, { label: 'Blue', value: 'blue' }),
),
],
});

Clicks go to bot.component(customId, handler). Answer with interaction.update(..) to change the message in place, interaction.reply(..) for a new message, or interaction.deferUpdate().

bot.component('a', (interaction) => interaction.update({ content: 'You picked A', components: [] }));
bot.component('colour', (interaction) =>
interaction.reply({ content: `Colour: ${interaction.values.join(', ')}`, ephemeral: true }));

Link buttons take https:// only, and readers confirm before they open.

A Components V2 message has no content or embeds: components carry everything. The flag can’t be removed later. In TypeScript, a reply whose components are layout builders (a container, section, text display, …) is sent as V2; in Rust, Reply::v2() or Reply::container(..) turns it on.

import {
ActionRowBuilder, ButtonBuilder, ButtonStyle, ContainerBuilder, SectionBuilder,
SeparatorBuilder, TextDisplayBuilder,
} from '@zaun/bot';
interaction.reply({
components: [
new ContainerBuilder().setAccentColor(0x5865f2)
.addTextDisplayComponents(new TextDisplayBuilder().setContent('## Release 1.2\nEverything new this week.'))
.addSeparatorComponents(new SeparatorBuilder())
.addSectionComponents(new SectionBuilder()
.addTextDisplayComponents(new TextDisplayBuilder().setContent('Read the notes'))
.setButtonAccessory(new ButtonBuilder().setCustomId('notes').setLabel('Open').setStyle(ButtonStyle.Primary)))
.addActionRowComponents(new ActionRowBuilder().addComponents(
new ButtonBuilder().setCustomId('ok').setLabel('Got it').setStyle(ButtonStyle.Success))),
],
});
type Component TypeScript builder Where Key fields and limits
1 Action Row ActionRowBuilder message, container 1–5 buttons or 1 select
2 Button ButtonBuilder action row, section accessory styles 1 primary, 2 secondary, 3 success, 4 danger, 5 link; label ≤ 80; emoji; custom id for 1–4
3 String Select StringSelectMenuBuilder action row, modal label ≤ 25 options; placeholder ≤ 150; min/max values 0–25
4 Text Input TextInputBuilder modal label short or paragraph; length 0–4 000
5–8 User / Role / Mentionable / Channel Select UserSelectMenuBuilder, RoleSelectMenuBuilder, MentionableSelectMenuBuilder, ChannelSelectMenuBuilder action row, modal label default values; channel types (8)
9 Section SectionBuilder V2 message, container 1–3 text displays + a button or thumbnail
10 Text Display TextDisplayBuilder V2 message, container, section, modal Markdown; ≤ 4 000 characters per message in all
11 Thumbnail ThumbnailBuilder section accessory an image attachment
12 Media Gallery MediaGalleryBuilder V2 message, container 1–10 attachments
13 File FileBuilder V2 message, container one attachment
14 Separator SeparatorBuilder V2 message, container divider; small or large spacing
17 Container ContainerBuilder V2 message children 1, 9, 10, 12, 13, 14; accent colour; spoiler
18 Label LabelBuilder modal label ≤ 45, description ≤ 100, one input
19 File Upload FileUploadBuilder modal label 0–10 files
21 Radio Group RadioGroupBuilder modal label 2–10 options
22 Checkbox Group CheckboxGroupBuilder modal label 1–10 options
23 Checkbox CheckboxBuilder modal label never required

Totals: classic messages up to 5 action rows; V2 messages up to 40 components counting nested ones. Custom ids are 1–100 bytes and unique per message or modal. Premium buttons are not supported.