Best way to get StringSelectMenuInteraction value from ButtonInteraction?

I have a StringSelect and a Button as my components. I want the user to select a value from the StringSelect, and then press the button to confirm. This is my current setup:
...
const selectRow = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(
new StringSelectMenuBuilder()
.setCustomId(`bounty-${interaction.id}-shop-item`)
.setPlaceholder("Select a reward to purchase")
.setOptions(options)
);

const buttonRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
.setCustomId(`bounty-${interaction.id}-shop-buy`)
.setLabel("Purchase")
.setStyle(ButtonStyle.Success)
);

await interaction.reply({ embeds: [embed], components: [selectRow, buttonRow], ephemeral: true });
...
const selectRow = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(
new StringSelectMenuBuilder()
.setCustomId(`bounty-${interaction.id}-shop-item`)
.setPlaceholder("Select a reward to purchase")
.setOptions(options)
);

const buttonRow = new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder()
.setCustomId(`bounty-${interaction.id}-shop-buy`)
.setLabel("Purchase")
.setStyle(ButtonStyle.Success)
);

await interaction.reply({ embeds: [embed], components: [selectRow, buttonRow], ephemeral: true });
export const HadesBountySelectMenuInteractionHandler = async (selectMenuInteraction: StringSelectMenuInteraction) => {
const originalInteractionId = selectMenuInteraction.message?.interaction?.id;

if (selectMenuInteraction.customId !== `bounty-${originalInteractionId}-shop-item`) {
return;
}

// get item from select menu
const selectedItem = selectMenuInteraction.values[0];

// get the item from the database
const shopItem = await GetBountyShopItem(selectedItem);
if (!shopItem || shopItem.quantity === 0) {
return await selectMenuInteraction.reply({ content: "Item is out of stock, please select another.", ephemeral: true })
}

return await selectMenuInteraction.deferUpdate();
}
export const HadesBountySelectMenuInteractionHandler = async (selectMenuInteraction: StringSelectMenuInteraction) => {
const originalInteractionId = selectMenuInteraction.message?.interaction?.id;

if (selectMenuInteraction.customId !== `bounty-${originalInteractionId}-shop-item`) {
return;
}

// get item from select menu
const selectedItem = selectMenuInteraction.values[0];

// get the item from the database
const shopItem = await GetBountyShopItem(selectedItem);
if (!shopItem || shopItem.quantity === 0) {
return await selectMenuInteraction.reply({ content: "Item is out of stock, please select another.", ephemeral: true })
}

return await selectMenuInteraction.deferUpdate();
}
export const HadesBountyButtonMenuInteractionHandler = async (buttonInteraction: ButtonInteraction) => {
const originalInteractionId = buttonInteraction.message?.interaction?.id;
if (!buttonInteraction.customId.includes(`bounty-${originalInteractionId}-shop-buy`)) {
return;
}

// get the select value here and process it
}
export const HadesBountyButtonMenuInteractionHandler = async (buttonInteraction: ButtonInteraction) => {
const originalInteractionId = buttonInteraction.message?.interaction?.id;
if (!buttonInteraction.customId.includes(`bounty-${originalInteractionId}-shop-buy`)) {
return;
}

// get the select value here and process it
}
11 Replies
d.js toolkit
d.js toolkit2mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
nullopt
nullopt2mo ago
It's more for additional confirmation as it will eventually charge the user.
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs2mo ago
:method: InteractionResponse#awaitMessageComponent @14.15.1 Collects a single component interaction that passes the filter. The Promise will reject if the time expires.
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
nullopt
nullopt2mo ago
interesting... thank you - I will look into this
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs2mo ago
:method: InteractionResponse#createMessageComponentCollector @14.15.1 Creates a message component interaction collector
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
nullopt
nullopt2mo ago
Oh yeh, was typing that bit out in discord will check this out, thanks
Want results from more Discord servers?
Add your server
More Posts