22title : Select Menus
33---
44
5- Select menus are one of the ` MessageComponent ` classes, which can be sent via messages or interaction responses.
5+ Select menus are interactive components which can be sent via messages, interaction responses, or in modals .
66
77<Callout >
88 This page is a follow-up to the [ slash commands] ( ../slash-commands/advanced-creation ) section and [ action
99 rows] ( ../interactive-components/action-rows ) page. Please carefully read those pages first so that you can understand
1010 the methods used here.
1111</Callout >
12+ <Callout >
13+ This page is for using select menus in messages. For using [ select menus in
14+ modals] ( ../interactions/modals#select-menu ) visit the modal page
15+ </Callout >
1216
1317## Building string select menus
1418
@@ -22,13 +26,17 @@ const { StringSelectMenuBuilder, StringSelectMenuOptionBuilder, SlashCommandBuil
2226module .exports = {
2327 // data: new SlashCommandBuilder()...
2428 async execute (interaction ) {
25- const select = new StringSelectMenuBuilder ()
29+ const favoriteStarterSelect = new StringSelectMenuBuilder ()
2630 .setCustomId (' starter' )
2731 .setPlaceholder (' Make a selection!' )
2832 .addOptions (
33+ // String select menu options
2934 new StringSelectMenuOptionBuilder ()
35+ // Label displayed to user
3036 .setLabel (' Bulbasaur' )
37+ // Description of option
3138 .setDescription (' The dual-type Grass/Poison Seed Pokémon.' )
39+ // Value returned in select menu interaction
3240 .setValue (' bulbasaur' ),
3341 new StringSelectMenuOptionBuilder ()
3442 .setLabel (' Charmander' )
@@ -59,17 +67,21 @@ const {
5967 StringSelectMenuOptionBuilder ,
6068 SlashCommandBuilder ,
6169} = require (' discord.js' );
62- // [!code focus:30 ]
70+ // [!code focus:33 ]
6371module .exports = {
6472 // data: new SlashCommandBuilder()...
6573 async execute (interaction ) {
66- const select = new StringSelectMenuBuilder ()
74+ const favoriteStarterSelect = new StringSelectMenuBuilder ()
6775 .setCustomId (' starter' )
6876 .setPlaceholder (' Make a selection!' )
6977 .addOptions (
78+ // String select menu options
7079 new StringSelectMenuOptionBuilder ()
80+ // Label displayed to user
7181 .setLabel (' Bulbasaur' )
82+ // Description of option
7283 .setDescription (' The dual-type Grass/Poison Seed Pokémon.' )
84+ // Value returned in select menu interaction
7385 .setValue (' bulbasaur' ),
7486 new StringSelectMenuOptionBuilder ()
7587 .setLabel (' Charmander' )
@@ -81,9 +93,11 @@ module.exports = {
8193 .setValue (' squirtle' ),
8294 );
8395
84- // [!code ++:6]
85- const row = new ActionRowBuilder ().addComponents (select);
96+ // [!code ++:8]
97+ // Adding a string select menu to an action row
98+ const row = new ActionRowBuilder ().addComponents (favoriteStarterSelect);
8699
100+ // Reply with the action row
87101 await interaction .reply ({
88102 content: ' Choose your starter!' ,
89103 components: [row],
@@ -99,7 +113,7 @@ module.exports = {
99113 components] ( ../popular-topics/display-components ) system.
100114</Callout >
101115
102- ### String select menu options
116+ ## String select menu options
103117
104118String select menu options are custom-defined by the user, as shown in the example above. At a minimum, each option must have it's ` label ` and ` value ` defined. The label is shown to the user, while the value is included in the interaction sent to the bot.
105119
0 commit comments