waiting for interaction collector to finish before executing another function

code:
await interaction.reply({ ephemeral: false, embeds: [embed], components: [row] }).catch(e => console.log(e));

let filter = i => [`next`, `exit`].includes(i.customId);
let collector = await interaction.channel.createMessageComponentCollector({ filter, max: 1, time: 20000 });
let endCon = 0;

collector.on('collect', async i => {
await i.deferUpdate();

if (i.customId === `next`) {
endCon = 1;
collector.emit('end', collected => { });
}
else if (i.customId === `exit`) {
collector.emit('end', collected => { });
}
else {
collector.emit('end', collected => { });
}
});

collector.on('end', async collected => {
if (endCon == 0) {
await interaction.editReply({ content: `Command exited/timed out. Please use this command again.`, components: [], embeds: [] }).catch(e => console.log(e));
} else {
await interaction.editReply({ content: `Continuing`, components: [], embeds: [] }).catch(e => console.log(e));
};
});

for (let i = 0; i < challengeData.story.length; i++) {
// to be implemented
}

await interaction.followUp(`This command is currently a work in progress.`);
await interaction.reply({ ephemeral: false, embeds: [embed], components: [row] }).catch(e => console.log(e));

let filter = i => [`next`, `exit`].includes(i.customId);
let collector = await interaction.channel.createMessageComponentCollector({ filter, max: 1, time: 20000 });
let endCon = 0;

collector.on('collect', async i => {
await i.deferUpdate();

if (i.customId === `next`) {
endCon = 1;
collector.emit('end', collected => { });
}
else if (i.customId === `exit`) {
collector.emit('end', collected => { });
}
else {
collector.emit('end', collected => { });
}
});

collector.on('end', async collected => {
if (endCon == 0) {
await interaction.editReply({ content: `Command exited/timed out. Please use this command again.`, components: [], embeds: [] }).catch(e => console.log(e));
} else {
await interaction.editReply({ content: `Continuing`, components: [], embeds: [] }).catch(e => console.log(e));
};
});

for (let i = 0; i < challengeData.story.length; i++) {
// to be implemented
}

await interaction.followUp(`This command is currently a work in progress.`);
discord.js v14.11.0 node.js v16.17.0 Goal: Have the interaction.followUp() statement run after MessageComponentCollector is finished collecting. What's happening currently: interaction.reply() and interaction.followUp() run right after the other, without waiting for the collector to finish
4 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
vivian <3
vivian <3OP2y ago
there's no way around it? the for loop after the end event is meant to execute multiple more message comp collectors, each time relying on data from the previous to execute. i want to see if i can do this without recursion
d.js docs
d.js docs2y ago
method Message#awaitMessageComponent() Collects a single component interaction that passes the filter. The Promise will reject if the time expires.
vivian <3
vivian <3OP2y ago
i took a look at the documentation. seems to only return the first interaction. is there any way to return all the interactions or do i need to promisify messagecomponentcollector myself? gotcha
Want results from more Discord servers?
Add your server