Button
Buttons are interactive elements users can click to trigger specific actions. They are ideal for creating interactive messages, such as confirmation prompts or menu navigation.
Usage
import { Button, execute } from 'sunar';
const button = new Button({ id: 'example' });
execute(button, (interaction) => {
// handle execution
});
export { button };Implementation
The following example demonstrates how to implement a Button using Sunar:
import { Button, Slash, execute } from 'sunar';
import {
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
PermissionFlagsBits,
} from 'discord.js';
const slash = new Slash({
name: 'leave',
description: 'Make the bot leave the server',
dmPermission: false,
defaultMemberPermissions: [PermissionFlagsBits.Administrator],
});
execute(slash, (interaction) => {
const button = new ButtonBuilder()
.setCustomId('confirmLeave')
.setLabel('Leave')
.setStyle(ButtonStyle.Danger);
const row = new ActionRowBuilder().setComponents(button);
interaction.reply({
content: 'Are you certain about my leaving the server?',
components: [row],
});
});
const button = new Button({ id: 'confirmLeave' });
execute(button, async (interaction) => {
await interaction.reply({
content: 'Leaving...',
ephemeral: true,
});
interaction.guild.leave();
});
export { slash, button };Reference
ButtonOptions
Prop
Type
ButtonConfig
Prop
Type
How is this guide?
Last updated on
Autocomplete
Autocomplete commands enhance the user experience by providing suggestions while the user is typing. They are particularly useful for commands with multiple options or extensive inputs.
ContextMenu
Context menu commands are available directly in the right-click context menu for users or messages. These commands are convenient for quick actions without needing to type a command.