CreateButton
CreateButton creates Discord button components for use inside CreateActionRow.
Import
Section titled “Import”import { CreateButton, ButtonType } from "lunibee";import { CreateButton, ButtonType } 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, non-premium buttons; max 100 characters). Throws on a link button.
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 (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);button.setStyle(ButtonType.Danger);setURL(url)
Section titled “setURL(url)”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");button.setStyle(ButtonType.Link).setURL("https://lunibee.js.org");setEmoji(emoji)
Section titled “setEmoji(emoji)”Adds an emoji to the button. A string becomes { name }.
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 (disabled defaults to true).
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 { 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: [] }); }});import { CreateActionRow, CreateButton, ButtonType } from "lunibee";
const row = new CreateActionRow().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] });const docsRow = new CreateActionRow().addComponents( new CreateButton() .setLabel("View Docs") .setStyle(ButtonType.Link) .setURL("https://lunibee.js.org") .setEmoji("📚"),);await channel.send({ content: "Need help?", components: [docsRow] });Styles and Validation (0.2.0)
Section titled “Styles and Validation (0.2.0)”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.