This command keeps on returning Interaction has already been acknowledged
. How can I solve this?
Here’s the code I’m currently using:
JavaScript
x
114
114
1
const {
2
SlashCommandBuilder,
3
EmbedBuilder,
4
ButtonStyle,
5
ButtonBuilder,
6
ActionRowBuilder,
7
ActionRow,
8
} = require("discord.js");
9
10
module.exports = {
11
data: new SlashCommandBuilder()
12
.setName("highlow")
13
.setDescription("👇 | Starts a new high or low game!"),
14
async execute(interaction) {
15
const randomNumber = Math.floor(Math.random() * 100) + 1;
16
const hintNumber = Math.floor(Math.random() * 100) + 1;
17
const row = new ActionRowBuilder().addComponents(
18
new ButtonBuilder()
19
.setLabel("High")
20
.setStyle("Secondary")
21
.setCustomId("high"),
22
new ButtonBuilder()
23
.setCustomId("low")
24
.setLabel("Low")
25
.setStyle("Secondary"),
26
new ButtonBuilder()
27
.setCustomId("correct")
28
.setLabel("Same")
29
.setStyle("Secondary")
30
);
31
const sent = await interaction.reply({
32
content: `Is my number higher or lower than ${hintNumber}?`,
33
components: [row],
34
fetchReply: true,
35
});
36
const collector = sent.createMessageComponentCollector({
37
filter: (i) =>
38
i.user.id === interaction.user.id && i.message.id === sent.id,
39
time: 30000,
40
max: 1,
41
});
42
let won = false;
43
collector.on("collect", async (i) => {
44
await i.deferUpdate({ fetchReply: true });
45
row.components.forEach((b) => b.setDisabled(true));
46
if (i.customId === "high") {
47
if (hintNumber > randomNumber) {
48
row.components.forEach((b) => {
49
if (b.customId === "high") b.setStyle("Danger");
50
});
51
await interaction.editReply({
52
content: `Sadge, you got it wrong! It was ${randomNumber}`,
53
components: [row],
54
});
55
won = false;
56
} else {
57
row.components.forEach((b) => {
58
if (b.customId === "high") b.setStyle("Success");
59
});
60
await interaction.editReply({
61
content: `You guessed the number! It was ${randomNumber}`,
62
components: [row],
63
});
64
won = true;
65
}
66
} else if (i.customId === "low") {
67
if (hintNumber < randomNumber) {
68
row.components.forEach((b) => {
69
if (b.customId === "low") b.setStyle("Danger");
70
});
71
await interaction.editReply({
72
content: `Sadge, you got it wrong! It was ${randomNumber}`,
73
components: [row],
74
});
75
won = false;
76
} else {
77
row.components.forEach((b) => {
78
if (b.customId === "low") b.setStyle("Success");
79
});
80
await interaction.editReply({
81
content: `You are right! It was ${randomNumber}`,
82
components: [row],
83
});
84
won = true;
85
}
86
} else if (i.customId === "correct" && hintNumber === randomNumber) {
87
row.components.forEach((b) => {
88
if (b.customId === "correct") b.setStyle("Success");
89
});
90
await interaction.editReply({
91
content: `You guessed the number! It was ${randomNumber}`,
92
components: [row],
93
});
94
won = true;
95
} else {
96
await interaction.editReply({
97
content: `Sadge, you got it wrong! It was ${randomNumber}`,
98
components: [row],
99
});
100
won = false;
101
}
102
});
103
collector.on("end", async (collected) => {
104
row.components.forEach((b) => b.setDisabled(true));
105
if (!won && collected.size === 0) {
106
await interaction.editReply({
107
content: `You didn't guess the number! It was ${randomNumber}`,
108
components: [row],
109
});
110
}
111
});
112
},
113
};
114
The error is showing:
JavaScript
1
22
22
1
C:UsersMatthewOneDriveDocumentsAyanokojinode_modules@discordjsrestdistlibhandlersSequentialHandler.cjs:293
2
throw new DiscordAPIError.DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
3
^
4
5
DiscordAPIError[40060]: Interaction has already been acknowledged.
6
at SequentialHandler.runRequest (C:UsersMatthewOneDriveDocumentsAyanokojinode_modules@discordjsrestdistlibhandlersSequentialHandler.cjs:293:15)
7
at processTicksAndRejections (node:internal/process/task_queues:96:5)
8
at async SequentialHandler.queueRequest (C:UsersMatthewOneDriveDocumentsAyanokojinode_modules@discordjsrestdistlibhandlersSequentialHandler.cjs:99:14)
9
at async REST.request (C:UsersMatthewOneDriveDocumentsAyanokojinode_modules@discordjsrestdistlibREST.cjs:52:22)
10
at async ButtonInteraction.deferUpdate (C:UsersMatthewOneDriveDocumentsAyanokojinode_modulesdiscord.jssrcstructuresinterfacesInteractionResponses.js:192:5)
11
at async InteractionCollector.<anonymous> (C:UsersMatthewOneDriveDocumentsAyanokojiinteractionsslashfunhighlow.js:44:4) {
12
rawError: {
13
message: 'Interaction has already been acknowledged.',
14
code: 40060
15
},
16
code: 40060,
17
status: 400,
18
method: 'POST',
19
url: 'https://discord.com/api/v10/interactions/1021755660406374452/aW50ZXJhY3Rpb246MTAyMTc1NTY2MDQwNjM3NDQ1MjpyMjViUU8xSGtzQ1dXZXVXbWh2YmRiczZ5ZldzcVhuYm1hNXdWWFRRSVlUUzk0MXFDV1M2NmRjQWF3MEJXTVo0TmN1UlR3U1QxQnUxVDd1YlZodjdnbnpNRVM5VlVSV1B0aUNSS2ZGZkQ5QURrdlFIenVHaUVZdTRkUmR5YnBVaQ/callback',
20
requestBody: { files: undefined, json: { type: 6 } }
21
}
22
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.