Skip to content

ButtonBuilder

ButtonBuilder creates Discord button components for use inside ActionRowBuilder.

import { ButtonBuilder, ButtonStyle } from "lunibee";

All methods return this for chaining.

Sets the custom ID for interactive buttons (required for non-link buttons).

button.setCustomId("confirm_action");

Sets the button label text (max 80 characters).

button.setLabel("Confirm");

Sets the button style. Use the ButtonStyle enum:

Constant Value Appearance
ButtonStyle.Primary 1 Blue
ButtonStyle.Secondary 2 Gray
ButtonStyle.Success 3 Green
ButtonStyle.Danger 4 Red
ButtonStyle.Link 5 URL link (gray, opens in browser)
button.setStyle(ButtonStyle.Danger);

Sets the URL for link buttons (ButtonStyle.Link). Link buttons cannot have a customId.

button.setStyle(ButtonStyle.Link).setURL("https://lunibee.js.org");

Adds an emoji to the button.

button.setEmoji("🚀");
button.setEmoji({ id: "123456789", name: "lunibee" });

Disables or enables the button.

button.setDisabled(true);

Serializes to a raw Discord component object.

Confirmation flow with two buttons

import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from "lunibee";
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
.setCustomId("confirm")
.setLabel("Confirm")
.setStyle(ButtonStyle.Success)
.setEmoji(""),
new ButtonBuilder()
.setCustomId("cancel")
.setLabel("Cancel")
.setStyle(ButtonStyle.Danger)
.setEmoji(""),
);
await channel.send({ content: "Are you sure?", components: [row] });
// Handle the button click:
client.on("interactionCreate", async (interaction) => {
if (!interaction.isComponent()) return;
if (interaction.customId === "confirm") {
await interaction.update({ content: "✅ Confirmed!", components: [] });
} else if (interaction.customId === "cancel") {
await interaction.update({ content: "❌ Cancelled.", components: [] });
}
});

Documentation link button

const docsRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
.setLabel("View Docs")
.setStyle(ButtonStyle.Link)
.setURL("https://lunibee.js.org")
.setEmoji("📚"),
);
await channel.send({ content: "Need help?", components: [docsRow] });