SelectMenus
The SelectMenus class builds discord.js select menu action rows; string, user, role, or channel select menus; from plain objects.
const { SelectMenus } = require("syntx.js");Creating a select menu
const menu = new SelectMenus([
{
menu_id: "color-picker",
content: "Pick a color",
fields: [
{ name: "Red", value: "red" },
{ name: "Green", value: "green" },
{ name: "Blue", value: "blue" },
],
},
]);Note
Each menu definition becomes its own action row. Discord doesn't allow more than one select menu per row anyway, so SelectMenus always puts one menu per row for you.
Menu definition
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
menu_id | string | Yes | — | The customId, read back in client.interaction(). |
type | "normal" | "user" | "role" | "channel" | No | "normal" | "normal" is a string select menu with your own fields. |
content | string | No | — | Placeholder text shown before a choice is made. |
min | number | No | 1 | Minimum number of choices required. |
max | number | No | 1 | Maximum number of choices allowed. |
fields | Field[] | "normal" only | [] | The selectable options. Ignored for user/role/channel. |
Warning
There's no "mentionable" type; only normal, user, role, and channel. If you need both users and roles selectable, use two separate menus.
new SelectMenus([
{
menu_id: "notify-roles",
type: "role",
content: "Choose roles to ping",
max: 5,
},
]);Field definition (normal menus only)
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
name | string | Yes | — | The label shown to the user. |
value | string | Yes | — | The value your code receives back. |
description | string | No | — | Small grey text under the label. |
default | boolean | No | false | Pre-selects this option. |
emoji | string | No | — | An emoji shown next to the label. |
new SelectMenus([
{
menu_id: "language",
fields: [
{ name: "English", value: "en", emoji: "🇬🇧" },
{ name: "Spanish", value: "es", emoji: "🇪🇸", description: "Español" },
],
},
]);build()
Returns an array of discord.js ActionRowBuilder, ready to pass to components.
message.reply({
content: "Choose an option:",
components: menu.build(),
});Handling a selection
client.interaction({
id: "color-picker",
content: (interaction) => {
interaction.reply(`You picked ${interaction.values[0]}`);
},
});
client.registerInteractions();Note
interaction.values holds the picked value(s) for every menu type. For user/role/channel menus, discord.js also resolves the full objects for you in interaction.users, interaction.roles, and interaction.channels.
Tip
Need text, images, or buttons alongside your menu in one layout? See Display, which builds the same kind of menu inside a "menu" block.