Unknown interaction, what could be the reason?
I am currently working on a bot that requests an api and then sends it back, the typical one. Everything worked and all interactions worked, but suddenly it stopped working. No interaction, be it commands or buttons, works anymore, the same error message always appears. I thought this could be because the interactions take too long, I tried defer etc. but it didn't help. What could be the reason for that?
- discord.js version:
thank you for your help :love:
14.18
- node version: v21.7.3
The exact error code is:
DiscordAPIError[10062]: Unknown interaction
at handleErrors (C:\Users\User\OneDrive\Desktop\secret test\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\User\OneDrive\Desktop\secret test\node_modules\@discordjs\rest\dist\index.js:831:23)
at async _REST.request (C:\Users\User\OneDrive\Desktop\secret\test\node_modules\@discordjs\rest\dist\index.js:1272:22)
at async ModalSubmitInteraction.reply (C:\Users\User\OneDrive\Desktop\secret\test\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:194:22)
The 'error' event was emitted on the client instance at:
at emitUnhandledRejectionOrErr (node:events:402:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21) {
requestBody: {
files: [],
json: {
type: 4,
data: {
content: 'Invalid User',
tts: false,
nonce: undefined,
enforce_nonce: false,
embeds: undefined,
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: 64,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined,
applied_tags: undefined,
poll: undefined
}
}
},
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
url: -'
}
DiscordAPIError[10062]: Unknown interaction
at handleErrors (C:\Users\User\OneDrive\Desktop\secret test\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\User\OneDrive\Desktop\secret test\node_modules\@discordjs\rest\dist\index.js:831:23)
at async _REST.request (C:\Users\User\OneDrive\Desktop\secret\test\node_modules\@discordjs\rest\dist\index.js:1272:22)
at async ModalSubmitInteraction.reply (C:\Users\User\OneDrive\Desktop\secret\test\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:194:22)
The 'error' event was emitted on the client instance at:
at emitUnhandledRejectionOrErr (node:events:402:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21) {
requestBody: {
files: [],
json: {
type: 4,
data: {
content: 'Invalid User',
tts: false,
nonce: undefined,
enforce_nonce: false,
embeds: undefined,
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: 64,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined,
applied_tags: undefined,
poll: undefined
}
}
},
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
url: -'
}
9 Replies
- 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!tag suggestion for @tryfyfu:
Common causes of
DiscordAPIError[10062]: Unknown interaction
:
- Initial response took more than 3 seconds ➞ defer the response *.
- Wrong interaction object inside a collector.
- Two processes handling the same command (the first consumes the interaction, so it won't be valid for the other instance)
* Note: you cannot defer modal or autocomplete value responsesshow how you tried deferring
// index.js Slash Commands Handler
client.on('interactionCreate', async interaction => {
if (interaction.type !== Discord.InteractionType.ApplicationCommand) return;
if (!interaction.guild) return interaction.reply({
content: "You can't use `/` commands in private messages",
});
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await interaction.deferReply();
await command.execute(interaction);
} catch (err) {
console.error(err);
await interaction.followUp({ content: "An error occurred while executing this command.", ephemeral: true });
}
});
// index.js Slash Commands Handler
client.on('interactionCreate', async interaction => {
if (interaction.type !== Discord.InteractionType.ApplicationCommand) return;
if (!interaction.guild) return interaction.reply({
content: "You can't use `/` commands in private messages",
});
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await interaction.deferReply();
await command.execute(interaction);
} catch (err) {
console.error(err);
await interaction.followUp({ content: "An error occurred while executing this command.", ephemeral: true });
}
});
The error happens when you try to reply to a modal submit interaction
Show that code
# creating modal
client.on("interactionCreate", async interaction => {
if(interaction.customId === "register_account_connect") {
const getAccountNameModal = new Discord.ModalBuilder()
.setTitle("Register Account")
.setCustomId("modal_register_account")
const TextInputAccount = new Discord.TextInputBuilder()
.setCustomId("text_in_game_name")
.setLabel("In-game Name")
.setRequired(true)
.setPlaceholder("<#820>tryfyfu")
.setStyle(Discord.TextInputStyle.Short)
const actionRow = new Discord.ActionRowBuilder().addComponents(TextInputAccount);
getAccountNameModal.addComponents(actionRow);
return interaction.showModal(getAccountNameModal)
}
});
# creating modal
client.on("interactionCreate", async interaction => {
if(interaction.customId === "register_account_connect") {
const getAccountNameModal = new Discord.ModalBuilder()
.setTitle("Register Account")
.setCustomId("modal_register_account")
const TextInputAccount = new Discord.TextInputBuilder()
.setCustomId("text_in_game_name")
.setLabel("In-game Name")
.setRequired(true)
.setPlaceholder("<#820>tryfyfu")
.setStyle(Discord.TextInputStyle.Short)
const actionRow = new Discord.ActionRowBuilder().addComponents(TextInputAccount);
getAccountNameModal.addComponents(actionRow);
return interaction.showModal(getAccountNameModal)
}
});
# receiving, part 1
client.on("interactionCreate", async interaction => {
if (interaction.customId === "modal_register_account") {
const ingamename = interaction.fields.getTextInputValue('text_in_game_name')
const userid = interaction.user.id
try {
const payload = { username: ingamename };
const response = await fetch(requestUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": authy,
"X-Forwarded-For": ip
},
body: JSON.stringify(payload)
});
if (!response.ok) {
throw new Error(`HTTP Error! Status: ${response.status}`);
}
const stats = await response.json();
const uid = stats.user_data.userId;
const name = stats.user_data.userName
const nameShow = processIngameName(stats.user_data.userName);
setCachedVerificationData(interaction.user.id, { stats, uid, name });
const existingAccount = await PlayerSchema.findOne({ stumble_uid: uid });
if (existingAccount) {
const linkedAccount = await PlayerSchema.findOne({ discord_user_id: userid });
if (linkedAccount) {
if (linkedAccount.stumble_uid != uid) {
const alreadyConnected = new Discord.EmbedBuilder()
.setColor("Red")
.setTitle("Account Already Connected")
.setDescription(`It seems that someone with ${nameShow} is already connected!\n\nIf this wasn't you, please contact support!`);
return interaction.reply({
embeds: [alreadyConnected],
ephemeral: true
});
} else if (linkedAccount.stumble_uid === uid) {
const changeAccount = new Discord.EmbedBuilder()
.setColor("Aqua")
.setTitle("Request Account Change")
.setDescription(`The in-game account ${nameShow} is already linked to your account!\n\nIf you want to cancel this process, click the **Cancel** button.`);
const btns1 = new Discord.ButtonBuilder()
.setLabel("Change")
.setCustomId("register_account_change")
.setStyle(Discord.ButtonStyle.Primary);
const btns2 = new Discord.ButtonBuilder()
.setLabel("Cancel")
.setCustomId("cancel_process")
.setStyle(Discord.ButtonStyle.Danger);
const btns = new Discord.ActionRowBuilder().addComponents(btns1, btns2);
return interaction.reply({
embeds: [changeAccount],
components: [btns],
ephemeral: true
});
}
}
# receiving, part 1
client.on("interactionCreate", async interaction => {
if (interaction.customId === "modal_register_account") {
const ingamename = interaction.fields.getTextInputValue('text_in_game_name')
const userid = interaction.user.id
try {
const payload = { username: ingamename };
const response = await fetch(requestUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": authy,
"X-Forwarded-For": ip
},
body: JSON.stringify(payload)
});
if (!response.ok) {
throw new Error(`HTTP Error! Status: ${response.status}`);
}
const stats = await response.json();
const uid = stats.user_data.userId;
const name = stats.user_data.userName
const nameShow = processIngameName(stats.user_data.userName);
setCachedVerificationData(interaction.user.id, { stats, uid, name });
const existingAccount = await PlayerSchema.findOne({ stumble_uid: uid });
if (existingAccount) {
const linkedAccount = await PlayerSchema.findOne({ discord_user_id: userid });
if (linkedAccount) {
if (linkedAccount.stumble_uid != uid) {
const alreadyConnected = new Discord.EmbedBuilder()
.setColor("Red")
.setTitle("Account Already Connected")
.setDescription(`It seems that someone with ${nameShow} is already connected!\n\nIf this wasn't you, please contact support!`);
return interaction.reply({
embeds: [alreadyConnected],
ephemeral: true
});
} else if (linkedAccount.stumble_uid === uid) {
const changeAccount = new Discord.EmbedBuilder()
.setColor("Aqua")
.setTitle("Request Account Change")
.setDescription(`The in-game account ${nameShow} is already linked to your account!\n\nIf you want to cancel this process, click the **Cancel** button.`);
const btns1 = new Discord.ButtonBuilder()
.setLabel("Change")
.setCustomId("register_account_change")
.setStyle(Discord.ButtonStyle.Primary);
const btns2 = new Discord.ButtonBuilder()
.setLabel("Cancel")
.setCustomId("cancel_process")
.setStyle(Discord.ButtonStyle.Danger);
const btns = new Discord.ActionRowBuilder().addComponents(btns1, btns2);
return interaction.reply({
embeds: [changeAccount],
components: [btns],
ephemeral: true
});
}
}
# receiving, part 2
else {
return interaction.reply({
content: "Error",
ephemeral: true
});
}
} else {
const howToVerify = new Discord.EmbedBuilder()
.setColor("Aqua")
.setTitle("How To Verify")
.setDescription(`You are trying to link the in-game account ${nameShow} to your Discord account.\n\nTo complete the connection, you need to verify yourself.\nEquip the **Mr. Stumble :MrStumble:** skin in-game and then click the **Verify** button.\n\nIf you want to cancel this process, click the **Cancel** button.`);
const btns1 = new Discord.ButtonBuilder()
.setLabel("Verify")
.setCustomId("register_account_verify")
.setStyle(Discord.ButtonStyle.Success);
const btns2 = new Discord.ButtonBuilder()
.setLabel("Cancel")
.setCustomId("cancel_process")
.setStyle(Discord.ButtonStyle.Danger);
const btns = new Discord.ActionRowBuilder().addComponents(btns1, btns2);
return interaction.reply({
embeds: [howToVerify],
components: [btns],
ephemeral: true
});
}
} catch (error) {
return interaction.reply({ content: "Invalid User", ephemeral: true });
}
}
})
# receiving, part 2
else {
return interaction.reply({
content: "Error",
ephemeral: true
});
}
} else {
const howToVerify = new Discord.EmbedBuilder()
.setColor("Aqua")
.setTitle("How To Verify")
.setDescription(`You are trying to link the in-game account ${nameShow} to your Discord account.\n\nTo complete the connection, you need to verify yourself.\nEquip the **Mr. Stumble :MrStumble:** skin in-game and then click the **Verify** button.\n\nIf you want to cancel this process, click the **Cancel** button.`);
const btns1 = new Discord.ButtonBuilder()
.setLabel("Verify")
.setCustomId("register_account_verify")
.setStyle(Discord.ButtonStyle.Success);
const btns2 = new Discord.ButtonBuilder()
.setLabel("Cancel")
.setCustomId("cancel_process")
.setStyle(Discord.ButtonStyle.Danger);
const btns = new Discord.ActionRowBuilder().addComponents(btns1, btns2);
return interaction.reply({
embeds: [howToVerify],
components: [btns],
ephemeral: true
});
}
} catch (error) {
return interaction.reply({ content: "Invalid User", ephemeral: true });
}
}
})
But its likely because you do a lot of async stuff, then reply
Defer first
And move all of that logic into a single listener, then handle based on which type of interaction it is
Error handling interaction: TypeError: fetch failed
at node:internal/deps/undici/undici:12500:13
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Client.<anonymous> (C:\Users\User\OneDrive\Desktop\secret\events\LinkAccount.js:39:30) {
[cause]: ConnectTimeoutError: Connect Timeout Error (attempted address: ip, timeout: 10000ms)
at onConnectTimeout (C:\Users\User\OneDrive\Desktop\secret\node_modules\undici\lib\core\connect.js:237:24)
at Immediate._onImmediate (C:\Users\User\OneDrive\Desktop\secret\node_modules\undici\lib\core\connect.js:188:35)
at process.processImmediate (node:internal/timers:478:21) {
code: 'UND_ERR_CONNECT_TIMEOUT'
}
}
Error handling interaction: TypeError: fetch failed
at node:internal/deps/undici/undici:12500:13
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Client.<anonymous> (C:\Users\User\OneDrive\Desktop\secret\events\LinkAccount.js:39:30) {
[cause]: ConnectTimeoutError: Connect Timeout Error (attempted address: ip, timeout: 10000ms)
at onConnectTimeout (C:\Users\User\OneDrive\Desktop\secret\node_modules\undici\lib\core\connect.js:237:24)
at Immediate._onImmediate (C:\Users\User\OneDrive\Desktop\secret\node_modules\undici\lib\core\connect.js:188:35)
at process.processImmediate (node:internal/timers:478:21) {
code: 'UND_ERR_CONNECT_TIMEOUT'
}
}