I'm trying to make a command with discord.js where you can choose from a choice of buttons. Then, the bot would edit the message depending of your choice.
So I added a collector to the interaction response with collector = commandMessage.createMessageComponentCollector({ componentType: ComponentType.Button, filter, time: 10000,max: 1}). I then added the 2 events collect and end handle for this collector.
But when I call my command multiple times ,the event end triggers only on the message of the last command call (even in different channels, it is as if the other collectors did not exist even though the others collectors should trigger their end after the timeout)
Here is the full code:
async execute(interaction) {
let quoteEmbed = new EmbedBuilder()
// [... creation of embed ...]
row = new ActionRowBuilder()
// [... creation of buttons ...]
commandMessage = await interaction.reply({ embeds: [quoteEmbed], components: [row], fetchReply: true });
const filter = (i) => i.user.id === interaction.user.id;
collector = commandMessage.createMessageComponentCollector({ componentType: ComponentType.Button, filter, time: 10000,max: 1});
collector.on('collect', async i => {
console.log(`Collected interaction for message ${i.message.id}`)
// Create new ActionRow to update
let newActionRowEmbeds = i.message.components.map(
// [... create new buttons from old one as disabled ...]
)
quoteEmbed = EmbedBuilder.from(i.message.embeds[0]);
// [... update embed ...]
await i.update({ embeds: [quoteEmbed], components: newActionRowEmbeds })
});
collector.on('end', async collected => {
console.log(`Collector of message ${collector.messageId} ended.`)
if (!collected.size) {
// Create new ActionRow to update
let newActionRowEmbeds = collector.options.message.components.map(
// [... create new buttons from old one as disabled ...]
)
quoteEmbed = EmbedBuilder.from(collector.options.message.embeds[0]);
// [... update embed ...]
await collector.options.message.edit({ embeds: [quoteEmbed], components: newActionRowEmbeds })
}
});
return commandMessage;
}
I feel like when I call the command while another collector is on, the new collector overwrites the previous one and then collector.options.message only gives me the last command call message.
But what is weird is that all calls end at their respect timeout times but each have collector.options.message with the same last message even though it is not the collector of this message.
Does anyone have an idea? I tried to reach for help in the discord.js server but with no success.