SelectMenus

The SelectMenus class builds discord.js select menu action rows; string, user, role, or channel select menus; from plain objects.

JavaScript
const { SelectMenus } = require("syntx.js");

Creating a select menu

JavaScript
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.

FieldTypeRequiredDefaultDescription
menu_idstringYesThe customId, read back in client.interaction().
type"normal" | "user" | "role" | "channel"No"normal""normal" is a string select menu with your own fields.
contentstringNoPlaceholder text shown before a choice is made.
minnumberNo1Minimum number of choices required.
maxnumberNo1Maximum number of choices allowed.
fieldsField[]"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.

JavaScript
new SelectMenus([
  {
    menu_id: "notify-roles",
    type: "role",
    content: "Choose roles to ping",
    max: 5,
  },
]);

Field definition (normal menus only)

FieldTypeRequiredDefaultDescription
namestringYesThe label shown to the user.
valuestringYesThe value your code receives back.
descriptionstringNoSmall grey text under the label.
defaultbooleanNofalsePre-selects this option.
emojistringNoAn emoji shown next to the label.
JavaScript
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.

JavaScript
message.reply({
  content: "Choose an option:",
  components: menu.build(),
});

Handling a selection

JavaScript
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.