ButtonBuilder
ButtonBuilder creates Discord button components for use inside ActionRowBuilder.
Import
Section titled “Import”import { ButtonBuilder, ButtonStyle } from "lunibee";import { ButtonBuilder, ButtonStyle } from "lunibee";Methods
Section titled “Methods”All methods return this for chaining.
setCustomId(id)
Section titled “setCustomId(id)”Sets the custom ID for interactive buttons (required for non-link buttons).
button.setCustomId("confirm_action");button.setCustomId("confirm_action");setLabel(label)
Section titled “setLabel(label)”Sets the button label text (max 80 characters).
button.setLabel("Confirm");button.setLabel("Confirm");setStyle(style)
Section titled “setStyle(style)”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);button.setStyle(ButtonStyle.Danger);setURL(url)
Section titled “setURL(url)”Sets the URL for link buttons (ButtonStyle.Link). Link buttons cannot have a customId.
button.setStyle(ButtonStyle.Link).setURL("https://lunibee.js.org");button.setStyle(ButtonStyle.Link).setURL("https://lunibee.js.org");setEmoji(emoji)
Section titled “setEmoji(emoji)”Adds an emoji to the button.
button.setEmoji("🚀");button.setEmoji({ id: "123456789", name: "lunibee" });button.setEmoji("🚀");button.setEmoji({ id: "123456789", name: "lunibee" });setDisabled(disabled?)
Section titled “setDisabled(disabled?)”Disables or enables the button.
button.setDisabled(true);button.setDisabled(true);toJSON()
Section titled “toJSON()”Serializes to a raw Discord component object.
Examples
Section titled “Examples”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: [] }); }});import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from "lunibee";
const row = new ActionRowBuilder().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] });const docsRow = new ActionRowBuilder().addComponents( new ButtonBuilder() .setLabel("View Docs") .setStyle(ButtonStyle.Link) .setURL("https://lunibee.js.org") .setEmoji("📚"),);await channel.send({ content: "Need help?", components: [docsRow] });