Skip to content

Buttons & Select Menus

Discord components allow users to trigger bot actions directly from messages.

import { CreateActionRow, CreateButton, ButtonType } from "lunibee";
client.on("messageCreate", async (message) => {
if (message.content === "!buttons") {
const accept = new CreateButton()
.setCustomId("btn_accept")
.setLabel("Accept")
.setStyle(ButtonType.Success);
const decline = new CreateButton()
.setCustomId("btn_decline")
.setLabel("Decline")
.setStyle(ButtonType.Danger);
const row = new CreateActionRow().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,
});
}
});