Series of component interactions

I have a flow in which I need a user to start with a context menu command, then I display a select menu with a set of categories, then display a set of roles based on the category selection, then add the role to the member the context command was used on. I was working on using collectors to do this, and I can get through the first one without issue, but I cant figgure out how to do the second menu succesfully.
response.resource.message
.awaitMessageComponent({
filter: collectorFilter,
time: 60_000,
})
.then(async (result) => {
await safeTry(result.deferUpdate());
if (!result.isStringSelectMenu()) return;
const term = result.values[0] ?? '';
const [classMenuError, response] = await safeTry(
interaction.editReply({
content: 'Select a class to add',
components: [buildClassSelectMenu(term, termGroupedRoles)],
flags: MessageFlags.Ephemeral,
withResponse: true,
}),
);
response.resource.message
.awaitMessageComponent({
filter: collectorFilter,
time: 60_000,
})
.then(async (result) => {
await safeTry(result.deferUpdate());
if (!result.isStringSelectMenu()) return;
const term = result.values[0] ?? '';
const [classMenuError, response] = await safeTry(
interaction.editReply({
content: 'Select a class to add',
components: [buildClassSelectMenu(term, termGroupedRoles)],
flags: MessageFlags.Ephemeral,
withResponse: true,
}),
);
I need help either getting this to work, or advice on a better setup. Normally I handle all interactions using the custom_id in an interaction handler, rather than with these collectors, but in this case I need the id of the member that the command was run on at the end of these menus and I am not sure how I would achieve that without the collector setup.
2 Replies
d.js toolkit
d.js toolkit•2w 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!
d.js docs
d.js docs•2w ago
:method: Message#createMessageComponentCollector() [email protected] Creates a message component interaction collector.
// Create a message component interaction collector
const filter = (interaction) => interaction.customId === 'button' && interaction.user.id === 'someId';
const collector = message.createMessageComponentCollector({ filter, time: 15_000 });
collector.on('collect', i => console.log(`Collected ${i.customId}`));
collector.on('end', collected => console.log(`Collected ${collected.size} items`));
// Create a message component interaction collector
const filter = (interaction) => interaction.customId === 'button' && interaction.user.id === 'someId';
const collector = message.createMessageComponentCollector({ filter, time: 15_000 });
collector.on('collect', i => console.log(`Collected ${i.customId}`));
collector.on('end', collected => console.log(`Collected ${collected.size} items`));

Did you find this page helpful?