"Interaction has already been acknowledged" after invoking a command twice in a row

Good morning, I've been encoutering an issue when trying to execute a command twice in a row. My button interaction collector is withing my command, with the code below :
const buttonsCollector =
interaction.channel.createMessageComponentCollector({
componentType: ComponentType.Button,
});

buttonsCollector.on('collect', async (buttonInteraction) => {
if (
buttonInteraction.user.id === interaction.user.id &&
buttonInteraction.customId.startsWith('Member')
) {
await handleButtons(
buttonInteraction,
member,
mulesSelectMenu,
buttons
);
} else {
await buttonInteraction.reply(
"Interaction impossible, tu n'es pas l'initiateur de la commande."
);
}
const buttonsCollector =
interaction.channel.createMessageComponentCollector({
componentType: ComponentType.Button,
});

buttonsCollector.on('collect', async (buttonInteraction) => {
if (
buttonInteraction.user.id === interaction.user.id &&
buttonInteraction.customId.startsWith('Member')
) {
await handleButtons(
buttonInteraction,
member,
mulesSelectMenu,
buttons
);
} else {
await buttonInteraction.reply(
"Interaction impossible, tu n'es pas l'initiateur de la commande."
);
}
In my handleButtons function, here's the case where I'm having the issue :
if (buttonInteraction.customId === 'MemberValidateEssaiButton') {
const validateEssaiMemberPseudo =
buttonInteraction.message.embeds[0].fields[1].value;
const updatedMember = await updateMember(
validateEssaiMemberPseudo,
'Rang',
'Membre'
);
const updatedEmbed = memberEmbed(updatedMember);
const updatedButtons = memberButtons(updatedMember);

await buttonInteraction.deferUpdate(); // this line raises the error
await buttonInteraction.editReply({
embeds: [updatedEmbed],
components: [updatedButtons],
});
if (buttonInteraction.customId === 'MemberValidateEssaiButton') {
const validateEssaiMemberPseudo =
buttonInteraction.message.embeds[0].fields[1].value;
const updatedMember = await updateMember(
validateEssaiMemberPseudo,
'Rang',
'Membre'
);
const updatedEmbed = memberEmbed(updatedMember);
const updatedButtons = memberButtons(updatedMember);

await buttonInteraction.deferUpdate(); // this line raises the error
await buttonInteraction.editReply({
embeds: [updatedEmbed],
components: [updatedButtons],
});
In addition, I see that the message still updates even if I get the error, so I'm a bit confused. Actually, note that once I clicked the button, my updatedButtons will not contain anymore the button that has been clicked. Could it be the reason of such an issue ? Thanks for your help
3 Replies
d.js toolkit
d.js toolkit14mo 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! - Marked as resolved by staff
d.js docs
d.js docs14mo ago
If you are waiting for button or select menu input from a specific message, don't create the collector on the channel. - Channel collectors return component interactions for any component within that channel.
- <Channel>.createMessageComponentCollector(…)
+ <Message>.createMessageComponentCollector(…)
- <Channel>.createMessageComponentCollector(…)
+ <Message>.createMessageComponentCollector(…)
Sourceae
SourceaeOP14mo ago
It worked, thanks.
Want results from more Discord servers?
Add your server