Skip to content

Buttons & Select Menus

Discord components allow users to trigger bot actions directly from message attachments.

import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from "lunibee";
client.on("messageCreate", async (message) => {
if (message.content === "!buttons") {
const accept = new ButtonBuilder()
.setCustomId("btn_accept")
.setLabel("Accept")
.setStyle(ButtonStyle.Success);
const decline = new ButtonBuilder()
.setCustomId("btn_decline")
.setLabel("Decline")
.setStyle(ButtonStyle.Danger);
const row = new ActionRowBuilder().addComponents(accept, decline);
await message.reply({
content: "Do you agree to the server rules?",
components: [row],
});
}
});
client.on("interactionCreate", async (interaction) => {
if (!interaction.isButton()) return;
if (interaction.customId === "btn_accept") {
await interaction.reply({
content: "Thank you for accepting the rules! 🎉",
ephemeral: true,
});
} else if (interaction.customId === "btn_decline") {
await interaction.reply({
content: "You declined the rules.",
ephemeral: true,
});
}
});