SelectMenu
Select menus allow users to choose from a list of options. They are useful for forms, surveys, or any scenario where the user needs to make a selection from multiple choices.
Usage
import { SelectMenu, execute } from 'sunar';
const select = new SelectMenu({
id: 'example',
type: ComponentType.StringSelect,
});
execute(select, (interaction) => {
// handle execution
});
export { select };Implementation
The following example demonstrates how to implement a Select Menu using Sunar:
import { SelectMenu, Slash, execute } from 'sunar';
import {
ActionRowBuilder,
ComponentType,
StringSelectMenuBuilder,
} from 'discord.js';
const slash = new Slash({
name: 'buy',
description: 'Buy something',
});
execute(slash, (interaction) => {
const select = new StringSelectMenuBuilder()
.setCustomId('buySelectMenu')
.setOptions(
{ label: 'Laptop', value: 'laptop' },
{ label: 'Smart TV', value: 'smart-tv' },
{ label: 'Tablet', value: 'tablet' },
{ label: 'Smartphone', value: 'smartphone' },
)
.setPlaceholder('Select an item to purchase');
const row = new ActionRowBuilder().setComponents(select);
interaction.reply({ components: [row] });
});
const select = new SelectMenu({
id: 'buySelectMenu',
type: ComponentType.StringSelect,
});
execute(select, (interaction) => {
const item = interaction.values.at(0);
// Do something with the item...
interaction.reply({ content: `You have purchased the **${item}** item` });
});
export { slash, select };Reference
SelectMenuOptions
Prop
Type
SelectMenuConfig
Prop
Type
How is this guide?
Last updated on
Protector
Protectors in Sunar act as middleware, allowing you to intercept and control the flow of commands and interactions within your Discord bot. They provide a flexible way to enforce permissions, validate inputs, or perform pre-processing before executing commands.
Signal
Signals in Sunar correspond to events in discord.js. They allow you to handle various actions and responses that occur within your Discord bot, such as messages being sent, users joining or leaving, and more.