Skip to content

CreateButton

CreateButton creates Discord button components for use inside CreateActionRow.

import { CreateButton, ButtonType } from "lunibee";

All methods return this for chaining.

Sets the custom ID for interactive buttons (required for non-link, non-premium buttons; max 100 characters). Throws on a link button.

button.setCustomId("confirm_action");

Sets the button label text (max 80 characters).

button.setLabel("Confirm");

Sets the button style (default ButtonType.Secondary). Use the ButtonType enum:

Constant Value Appearance
ButtonType.Primary 1 Blue
ButtonType.Secondary 2 Gray
ButtonType.Success 3 Green
ButtonType.Danger 4 Red
ButtonType.Link 5 URL link (gray, opens in browser)
ButtonType.Premium 6 Purchase button for a SKU (see setSKUId)
button.setStyle(ButtonType.Danger);

Sets the URL for link buttons and switches the style to ButtonType.Link (dropping any custom ID). The URL must be valid, at most 512 characters, and use http, https or discord. Link buttons cannot have a customId.

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

Adds an emoji to the button. A string becomes { name }.

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

Disables or enables the button (disabled defaults to true).

button.setDisabled(true);

Serializes to a raw Discord component object.

Confirmation flow with two buttons

import { CreateActionRow, CreateButton, ButtonType } from "lunibee";
const row = new CreateActionRow<CreateButton>().addComponents(
new CreateButton()
.setCustomId("confirm")
.setLabel("Confirm")
.setStyle(ButtonType.Success)
.setEmoji("✅"),
new CreateButton()
.setCustomId("cancel")
.setLabel("Cancel")
.setStyle(ButtonType.Danger)
.setEmoji("❌"),
);
await channel.send({ content: "Are you sure?", components: [row] });
// Handle the button click:
client.on("interactionCreate", async (interaction) => {
if (!interaction.isMessageComponent()) 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 CreateActionRow<CreateButton>().addComponents(
new CreateButton()
.setLabel("View Docs")
.setStyle(ButtonType.Link)
.setURL("https://lunibee.js.org")
.setEmoji("📚"),
);
await channel.send({ content: "Need help?", components: [docsRow] });
  • setSKUId(skuId) makes a premium (purchase) button.
  • setStyle() drops fields the new style cannot carry: link buttons have a URL and no custom ID or SKU; premium buttons have only a SKU; other styles have a custom ID and no URL or SKU.
  • toJSON() throws when required fields are missing (custom ID, URL or SKU for the style; a label or emoji for non-premium buttons) or when fields that the style forbids are set.