This command keeps on returning Interaction has already been acknowledged
. How can I solve this?
Here’s the code I’m currently using:
const { SlashCommandBuilder, EmbedBuilder, ButtonStyle, ButtonBuilder, ActionRowBuilder, ActionRow, } = require("discord.js"); module.exports = { data: new SlashCommandBuilder() .setName("highlow") .setDescription("👇 | Starts a new high or low game!"), async execute(interaction) { const randomNumber = Math.floor(Math.random() * 100) + 1; const hintNumber = Math.floor(Math.random() * 100) + 1; const row = new ActionRowBuilder().addComponents( new ButtonBuilder() .setLabel("High") .setStyle("Secondary") .setCustomId("high"), new ButtonBuilder() .setCustomId("low") .setLabel("Low") .setStyle("Secondary"), new ButtonBuilder() .setCustomId("correct") .setLabel("Same") .setStyle("Secondary") ); const sent = await interaction.reply({ content: `Is my number higher or lower than ${hintNumber}?`, components: [row], fetchReply: true, }); const collector = sent.createMessageComponentCollector({ filter: (i) => i.user.id === interaction.user.id && i.message.id === sent.id, time: 30000, max: 1, }); let won = false; collector.on("collect", async (i) => { await i.deferUpdate({ fetchReply: true }); row.components.forEach((b) => b.setDisabled(true)); if (i.customId === "high") { if (hintNumber > randomNumber) { row.components.forEach((b) => { if (b.customId === "high") b.setStyle("Danger"); }); await interaction.editReply({ content: `Sadge, you got it wrong! It was ${randomNumber}`, components: [row], }); won = false; } else { row.components.forEach((b) => { if (b.customId === "high") b.setStyle("Success"); }); await interaction.editReply({ content: `You guessed the number! It was ${randomNumber}`, components: [row], }); won = true; } } else if (i.customId === "low") { if (hintNumber < randomNumber) { row.components.forEach((b) => { if (b.customId === "low") b.setStyle("Danger"); }); await interaction.editReply({ content: `Sadge, you got it wrong! It was ${randomNumber}`, components: [row], }); won = false; } else { row.components.forEach((b) => { if (b.customId === "low") b.setStyle("Success"); }); await interaction.editReply({ content: `You are right! It was ${randomNumber}`, components: [row], }); won = true; } } else if (i.customId === "correct" && hintNumber === randomNumber) { row.components.forEach((b) => { if (b.customId === "correct") b.setStyle("Success"); }); await interaction.editReply({ content: `You guessed the number! It was ${randomNumber}`, components: [row], }); won = true; } else { await interaction.editReply({ content: `Sadge, you got it wrong! It was ${randomNumber}`, components: [row], }); won = false; } }); collector.on("end", async (collected) => { row.components.forEach((b) => b.setDisabled(true)); if (!won && collected.size === 0) { await interaction.editReply({ content: `You didn't guess the number! It was ${randomNumber}`, components: [row], }); } }); }, };
The error is showing:
C:UsersMatthewOneDriveDocumentsAyanokojinode_modules@discordjsrestdistlibhandlersSequentialHandler.cjs:293 throw new DiscordAPIError.DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData); ^ DiscordAPIError[40060]: Interaction has already been acknowledged. at SequentialHandler.runRequest (C:UsersMatthewOneDriveDocumentsAyanokojinode_modules@discordjsrestdistlibhandlersSequentialHandler.cjs:293:15) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async SequentialHandler.queueRequest (C:UsersMatthewOneDriveDocumentsAyanokojinode_modules@discordjsrestdistlibhandlersSequentialHandler.cjs:99:14) at async REST.request (C:UsersMatthewOneDriveDocumentsAyanokojinode_modules@discordjsrestdistlibREST.cjs:52:22) at async ButtonInteraction.deferUpdate (C:UsersMatthewOneDriveDocumentsAyanokojinode_modulesdiscord.jssrcstructuresinterfacesInteractionResponses.js:192:5) at async InteractionCollector.<anonymous> (C:UsersMatthewOneDriveDocumentsAyanokojiinteractionsslashfunhighlow.js:44:4) { rawError: { message: 'Interaction has already been acknowledged.', code: 40060 }, code: 40060, status: 400, method: 'POST', url: 'https://discord.com/api/v10/interactions/1021755660406374452/aW50ZXJhY3Rpb246MTAyMTc1NTY2MDQwNjM3NDQ1MjpyMjViUU8xSGtzQ1dXZXVXbWh2YmRiczZ5ZldzcVhuYm1hNXdWWFRRSVlUUzk0MXFDV1M2NmRjQWF3MEJXTVo0TmN1UlR3U1QxQnUxVDd1YlZodjdnbnpNRVM5VlVSV1B0aUNSS2ZGZkQ5QURrdlFIenVHaUVZdTRkUmR5YnBVaQ/callback', requestBody: { files: undefined, json: { type: 6 } } }
Advertisement
Answer
On line 44: await i.deferUpdate({ fetchReply: true });
It makes the error because the interaction has already been replied to. The error should go away when you remove this line. You also should replace await interaction.editReply
with interaction.followUp
on line 51, 60, 71, 80, 90, 96 and 106. And yup I answer your question again.