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:
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
}