const filter = (interaction) => {
if (interaction.user.id === message.author.id) return true;
return interaction.reply({
content: "An error has occurred",
ephemeral: true
})
}
const collectorValue1 = message.channel.createMessageComponentCollector({
filter,
max: 1
})
collectorValue1.on("end", (ButtonInteraction) => {
const id = ButtonInteraction.first().customId;
if (id == '1') {
ButtonInteraction.first().reply({
content: "CONTENT",
ephemeral: true
})
} else if (id == '2') {
ButtonInteraction.first().reply({
content: "CONTENT",
ephemeral: true
})
} else if (id == '3') {
ButtonInteraction.first().reply({
content: "CONTENT.",
ephemeral: true
})
}
})
I would like when the buttons are created they are multiple executable, however I can only use the button once, after that I always get the message "This interaction failed." how can I make the buttons multiple executable?
Please try the following:
collectorValue1.on("end", (ButtonInteraction) => {
ButtonInteraction.deferUpdate();
const id = ButtonInteraction.first().customId;
if (id == '1') {
ButtonInteraction.first().editReply({
content: "CONTENT",
ephemeral: true
})
Use deferUpdate() in the same way on each of the if statements. However, please note that when using deferUpdate(), you will need to change the .reply() method to .editReply().
You might try putting the deferUpdate() in the filter definition.
There is not much guidance on the Discord.js website, or documentation on using deferUpdate(). However, glean what you can from the documentation. Here is an example from the docs:
// Defer updating and reset the component's loading state
interaction.deferUpdate()
.then(console.log)
.catch(console.error);
Notably, the comment mentions that it "resets the component's loading state". I believe this is related to how it allows for using a button several times.
I hope this was helpful :]