In Discord MessageButtons, MessageActionRow
I'm having a MessageActionRow() running into a message embed, added buttons addComponents to that message, on createInteraction when a "PauseButton" is clicked, the button replaces with another button called "ResumeButton", same same.
const PauseButton = new MessageButton()
.setCustomId('PauseButton')
.setLabel('Pause')
.setStyle('SUCCESS')
.setEmoji('⏸️');
const ResumeButton = new MessageButton()
.setCustomId('ResumeButton')
.setLabel('Resume')
.setStyle('SUCCESS')
.setEmoji('▶️');
//SkipButton, StopButton
const Buttons = new MessageActionRow().addComponents(PauseButton, SkipButton, StopButton);
const ResumeButtons = new MessageActionRow().addComponents(ResumeButton, SkipButton, StopButton);
const sendMessage = await QueueChannel.send({ embeds: [sendMessageEmbed], components: [Buttons] });
this.client.on('interactionCreate', async interaction => {
if (!interaction.isButton()) return;
// Pause
if (interaction.customId === "PauseButton") {
player.pause(true);
const int = await interaction.deferUpdate({
fetchReply: true,
});
if (!int) return smt
await int.edit({
components: [ResumeButtons],
});
if(int.deleted) {
interaction.channel.send()
}
}
// Resume
if (interaction.customId === "ResumeButton") {
player.pause(false);
const int = await interaction.deferUpdate({
fetchReply: true,
});
if (!int) return smt
await int.edit({
components: [Buttons],
});
if(int.deleted) {
interaction.channel.send()
}
}
This returns the error DiscordAPIError: Unknown interaction ln line 23:13 await interaction.deferUpdate on await.
Basically, the code does the job (it works fully functional) except:
On the First run, everything works fine,
On the Second run, when I click any button, an error returns "Unknown interaction"
and the reason is that the the code is running twice, I knew when I added console.log("PauseButton") on the interact, the log returned twice to console PauseButton PauseButton instead of once.
Meaning there are 2 listeners for the ineractionCreate or something? Do I need to remove any interaction when the message is removed?
I need help please, anything is appreciated!
The process was duplicating because I had an interactionCreate.js in that project. I felt so confused because there was so many files, code has no issues, my apologize.