Ephemeral messages

My problem is that the error message is Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred. and not only DiscordAPIError[40060]: Interaction has already been recognized. they happen because of my ephemeral messages, for example, I have a main message with several buttons, all buttons send messages from ephemeral, ephemeral messages have a couple more buttons, for example, to scroll through the rules pages, if I scroll to some and close the ephemeral message that is visible only to me. The next time you open it, it will give you similar errors, is there any way to fix this?
16 Replies
d.js toolkit
d.js toolkit3w 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!
treble/luna
treble/luna3w ago
show your code
pal3st1na
pal3st1naOP3w ago
I can send the file in the format.js, many lines
d.js docs
d.js docs3w ago
To share long code snippets, use a service like gist, sourcebin, pastebin, or similar instead of posting them as large code blocks or files.
pal3st1na
pal3st1naOP3w ago
ok!
pal3st1na
pal3st1naOP3w ago
it seems to have been published https://pastebin.com/zMegmhvN
Pastebin
123.js - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
pal3st1na
pal3st1naOP3w ago
The code in most spaghetti:akpopKrinj:
d.js docs
d.js docs3w 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(…)
pal3st1na
pal3st1naOP3w ago
Thank you, this solved the problem when switching pages, sorry, but what about modal forms? they also have such errors when sending Do you know what this might be related to?:Frogroll: No, unfortunately it didn't help. After launching the bot, I send a modal form from one discord account, everything is fine with it and there are no errors in the process, but if someone decides to send another modal form after me, the bot will crash By issuing errors in the console DiscordAPIError[40060]: Interaction has already been acknowledged. DiscordAPIError[10062]: Unknown interaction
else if (i.customId === "completeTask") {
const uniqueId = `${interaction.user.id}-${Date.now()}`; // Unique identifier
const modal = new ModalBuilder()
.setCustomId(`submitTaskModal-${uniqueId}`)
.setTitle("Submit Task")
.addComponents(
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId("taskInput")
.setLabel("Enter task (format: W1, R1)")
.setStyle(TextInputStyle.Short)
.setPlaceholder("Example: W1, R1")
.setRequired(true)
),
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId("proofLink")
.setLabel("Proof link")
.setStyle(TextInputStyle.Short)
.setPlaceholder("Example: https://i.imgur.com/bWhx7OT.png")
.setRequired(false)
)
);

await i.showModal(modal);
return;
}
else if (i.customId === "completeTask") {
const uniqueId = `${interaction.user.id}-${Date.now()}`; // Unique identifier
const modal = new ModalBuilder()
.setCustomId(`submitTaskModal-${uniqueId}`)
.setTitle("Submit Task")
.addComponents(
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId("taskInput")
.setLabel("Enter task (format: W1, R1)")
.setStyle(TextInputStyle.Short)
.setPlaceholder("Example: W1, R1")
.setRequired(true)
),
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId("proofLink")
.setLabel("Proof link")
.setStyle(TextInputStyle.Short)
.setPlaceholder("Example: https://i.imgur.com/bWhx7OT.png")
.setRequired(false)
)
);

await i.showModal(modal);
return;
}
I think I fixed it in the handler. console.log gives out the id of the person who interacts every time, but the problem remains the same, when someone second after me starts interacting, the bot crashes
interaction.client.on("interactionCreate", async (interaction) => {
try {
if (interaction.type === InteractionType.ModalSubmit && interaction.customId.startsWith("submitTaskModal-")) {
const uniqueId = interaction.customId.split('-')[1];

if (interaction.replied || interaction.deferred) return;

await interaction.deferReply({ ephemeral: true });

const taskInput = interaction.fields.getTextInputValue("taskInput");
const proofLink = interaction.fields.getTextInputValue("proofLink");

console.log(`Processing submission with uniqueId: ${uniqueId}`);
interaction.client.on("interactionCreate", async (interaction) => {
try {
if (interaction.type === InteractionType.ModalSubmit && interaction.customId.startsWith("submitTaskModal-")) {
const uniqueId = interaction.customId.split('-')[1];

if (interaction.replied || interaction.deferred) return;

await interaction.deferReply({ ephemeral: true });

const taskInput = interaction.fields.getTextInputValue("taskInput");
const proofLink = interaction.fields.getTextInputValue("proofLink");

console.log(`Processing submission with uniqueId: ${uniqueId}`);
treble/luna
treble/luna3w ago
Thats gonna cause more issues, and is the reason you encounter your issue You can't nest listeners
d.js docs
d.js docs3w ago
:method: ButtonInteraction#awaitModalSubmit() @14.16.3 Collects a single modal submit interaction that passes the filter. The Promise will reject if the time expires.
// Collect a modal submit interaction
const filter = (interaction) => interaction.customId === 'modal';
interaction.awaitModalSubmit({ filter, time: 15_000 })
.then(interaction => console.log(`${interaction.customId} was submitted!`))
.catch(console.error);
// Collect a modal submit interaction
const filter = (interaction) => interaction.customId === 'modal';
interaction.awaitModalSubmit({ filter, time: 15_000 })
.then(interaction => console.log(`${interaction.customId} was submitted!`))
.catch(console.error);
treble/luna
treble/luna3w ago
Use that
pal3st1na
pal3st1naOP3w ago
It seems to me that I am doing something wrong, I entered your code into mine, logs in the console that the modal form has been sent, but still issues errors when users send this modal form after me, the error pops up when the 2nd user sends, and if the 3rd sends, then the bot will crash console =>
submitTaskModal-680046529733459980-1733326045987 was submitted!
submitTaskModal-1232719397794091038-1733326067283 was submitted!
Error handling interaction: DiscordAPIError[40060]: Interaction has already been acknowledged.
at handleErrors (C:\Users\ivale\Desktop\obl.ds.bott\node_modules\@discordjs\rest\dist\index.js:727:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (C:\Users\ivale\Desktop\obl.ds.bott\node_modules\@discordjs\rest\dist\index.js:831:23)
at async _REST.request (C:\Users\ivale\Desktop\obl.ds.bott\node_modules\@discordjs\rest\dist\index.js:1272:22)
at async ModalSubmitInteraction.deferReply (C:\Users\ivale\Desktop\obl.ds.bott\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:72:5)
at async Client.<anonymous> (C:\Users\ivale\Desktop\obl.ds.bott\src\commands\batlepass\tasks.js:258:7) {
requestBody: { files: undefined, json: { type: 5, data: [Object] } },
rawError: {
message: 'Interaction has already been acknowledged.',
code: 40060
},
code: 40060,
status: 400,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1313889510232293386/aW50ZXJhY3Rpb246MTMxMzg4OTUxMDIzMjI5MzM4NjpjVXZ2WWRhakM5WHdYemFIZFg2ZmlNZVlINDV4WmlKVUdCS29TbkN2RVk3d1Jwak8xOVRCNDFHbG44Rkp2OUw3bnB1UlZlZUdHWlZ3bXRNbFlnTHNtdEliYmJLdmpySnZxMG91NGx3cnNXUk9UbFNlS2Vnc2wwQjRIa2YwRWZvQw/callback'
}
submitTaskModal-680046529733459980-1733326045987 was submitted!
submitTaskModal-1232719397794091038-1733326067283 was submitted!
Error handling interaction: DiscordAPIError[40060]: Interaction has already been acknowledged.
at handleErrors (C:\Users\ivale\Desktop\obl.ds.bott\node_modules\@discordjs\rest\dist\index.js:727:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (C:\Users\ivale\Desktop\obl.ds.bott\node_modules\@discordjs\rest\dist\index.js:831:23)
at async _REST.request (C:\Users\ivale\Desktop\obl.ds.bott\node_modules\@discordjs\rest\dist\index.js:1272:22)
at async ModalSubmitInteraction.deferReply (C:\Users\ivale\Desktop\obl.ds.bott\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:72:5)
at async Client.<anonymous> (C:\Users\ivale\Desktop\obl.ds.bott\src\commands\batlepass\tasks.js:258:7) {
requestBody: { files: undefined, json: { type: 5, data: [Object] } },
rawError: {
message: 'Interaction has already been acknowledged.',
code: 40060
},
code: 40060,
status: 400,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1313889510232293386/aW50ZXJhY3Rpb246MTMxMzg4OTUxMDIzMjI5MzM4NjpjVXZ2WWRhakM5WHdYemFIZFg2ZmlNZVlINDV4WmlKVUdCS29TbkN2RVk3d1Jwak8xOVRCNDFHbG44Rkp2OUw3bnB1UlZlZUdHWlZ3bXRNbFlnTHNtdEliYmJLdmpySnZxMG91NGx3cnNXUk9UbFNlS2Vnc2wwQjRIa2YwRWZvQw/callback'
}
treble/luna
treble/luna3w ago
Show your code
pal3st1na
pal3st1naOP3w ago
Pastebin
123.js - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
treble/luna
treble/luna3w ago
so no, you are not using what i told you Not correctly at least .
Want results from more Discord servers?
Add your server