Adding options of select menu in if statements using select menu builder before it is sent

I have a question about updating components. I have it so in the function it previously does up to this:
let menu = new ActionRowBuilder()
.addComponents(
new StringSelectMenuBuilder()
.setCustomId('listFieldsEmbedBuilder')
.setPlaceholder('Select one:')
.setMaxValues(1)
.setMinValues(1),
);
let menu = new ActionRowBuilder()
.addComponents(
new StringSelectMenuBuilder()
.setCustomId('listFieldsEmbedBuilder')
.setPlaceholder('Select one:')
.setMaxValues(1)
.setMinValues(1),
);
and then later I try this within an if statement:
menu.setComponents(
StringSelectMenuBuilder.from(menu.components[0].data)
.addOptions({ label: 'Create', value: 'newField', description: 'Create a new field in the message.' }));
menu.setComponents(
StringSelectMenuBuilder.from(menu.components[0].data)
.addOptions({ label: 'Create', value: 'newField', description: 'Create a new field in the message.' }));
and I have it do it once more after another if statement. In some cases, it'll pass through both statements. How can I solve this so it stays within the same select menu?
7 Replies
Unknown User
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
leguchi
leguchiOP•2y ago
14.7.1, v18.1.0 How can I make it so I use part of the ActionRowBuilder() to create the select menu then later add more options to it? << is the simplified version of the question 🙂
ShompiFlen
ShompiFlen•2y ago
Hm... if you are constructing the select menu before sending it, then instead of creating the entire action row, just create the select menu first const selectMenu = new StringSelectMenuBuilder() then in your if statements, add the new options like this selectMenu.addOptions(theoption) finally at the end add the select menu to the action row const row = new ActionRowBuilder().addComponents(selectMenu)catOwo
leguchi
leguchiOP•2y ago
Okay I will try this out, thank you!
ShompiFlen
ShompiFlen•2y ago
sure, please tell if you have any issues
leguchi
leguchiOP•2y ago
Amazing, it works, thank you very much!
ShompiFlen
ShompiFlen•2y ago
AlfaThumbsUp
Want results from more Discord servers?
Add your server