I'm trying to create a code that will create the required number of menu selects and then respond to them after clicking. I create my menu select like this
for(i = 0; i < arr.length; i ) {
select.addOptions([
{
label: `${i}`,
value: `value${i}`,
description: `${i} role` }
])
}
Where arr.length
- required number of selects. I just can't figure out how to get the value on this select menu. I'd be happy to even have a hint! Thanks
CodePudding user response:
select.addOptions()
takes in an Array of options, so you could do it this way:
let selectarr = [];
for(i = 0; i < arr.length; i ) {
selectarr.push({
label: `{i}`,
description: `value${i}`,
value: `${i} role`,
});
}
select.addOptions(selectarr)
The comment:
//Create select menu const select = new ActionRowBuilder().addComponents( new StringSelectMenuBuilder() .setCustomId("your id")
.setPlaceholder("Your palceholder")
.addOptions(selectarr) );
//Reply
const sendResult = interaction.channel.send({ content: "Your text", embeds: [if you have an embed], components: [select], });
CodePudding user response:
I found solution, but I think there is a more reasonable solution to my problem, I give you my version
const select = new StringSelectMenuBuilder()
.setCustomId(`newTest`)
.setMaxValues(1)
.setPlaceholder(`Placeholder`)
const clearArr = []
for(i = 0; i < arr.length; i ) {
clearArr.push(i)
select.addOptions([
{
label: `${i}`,
value: `value${i}`,
description: `${i} role`,
}
])
}
const row = new ActionRowBuilder()
.addComponents(buttons)
let sendmsg = await message.channel.send(); // your message
const collector = sendmsg.createMessageComponentCollector({
componentType: ComponentType.StringSelect,
});
collector.on("collect", async (collected) => {
const value = collected.values[0];
for(const check of mas) {
if(value == `value${check}`) {
message.channel.send(`hi`)
}
}
});
thanks to everyone who tried to help :)