unknown interaction error

hey, i get the below error. I have tried to add an acknowledgement to the interaction, as we get the response from the API, so could take a while, but it still errors. It's intermittent.
await command.execute(interaction);
} catch (error) {
console.error(error);
// Handle errors only if the interaction hasn't been replied or deferred
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
> await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});
client.on(Events.InviteDelete, async invite => {
if(!botEnabled()) return;
const guildId = invite.guild.id;
await command.execute(interaction);
} catch (error) {
console.error(error);
// Handle errors only if the interaction hasn't been replied or deferred
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
> await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});
client.on(Events.InviteDelete, async invite => {
if(!botEnabled()) return;
const guildId = invite.guild.id;
DiscordAPIError[10062]: Unknown interaction
at handleErrors (/app/node_modules/@discordjs/rest/dist/index.js:722:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (/app/node_modules/@discordjs/rest/dist/index.js:826:23)
at async _REST.request (/app/node_modules/@discordjs/rest/dist/index.js:1266:22)
at async ChatInputCommandInteraction.deferReply (/app/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:69:5)
at async Object.execute (file:///app/src/commands.js:45:5)
at async Client.<anonymous> (file:///app/src/bot.js:62:3) {
requestBody: { files: undefined, json: { type: 5, data: [Object] } },
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1327467424752341022/aW50ZXJhY3Rpb246MTMyNzQ2NzQyNDc1MjM0MTAyMjo3OTdrdXl0RlhESWZjaFM4d01XRm5keGNaNUFwR3FFY0RRbVp6TG1hemt6Tm8wejdtYW1CSWxqUWZHTDJUT2RTdzlSWEU0bHZHQ0g1aHY2cDJjVmJSczRhU3BCMDNncU03akFESzVnczJNNDNWQTl0ZDZsaHBTWkJOb29yOTZ0bQ/callback'
}
DiscordAPIError[10062]: Unknown interaction
at handleErrors (/app/node_modules/@discordjs/rest/dist/index.js:722:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (/app/node_modules/@discordjs/rest/dist/index.js:826:23)
at async _REST.request (/app/node_modules/@discordjs/rest/dist/index.js:1266:22)
at async ChatInputCommandInteraction.reply (/app/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:111:5)
at async Client.<anonymous> (file:///app/src/bot.js:69:4) {
requestBody: { files: [], json: { type: 4, data: [Object] } },
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1327467424752341022/aW50ZXJhY3Rpb246MTMyNzQ2NzQyNDc1MjM0MTAyMjo3OTdrdXl0RlhESWZjaFM4d01XRm5keGNaNUFwR3FFY0RRbVp6TG1hemt6Tm8wejdtYW1CSWxqUWZHTDJUT2RTdzlSWEU0bHZHQ0g1aHY2cDJjVmJSczRhU3BCMDNncU03akFESzVnczJNNDNWQTl0ZDZsaHBTWkJOb29yOTZ0bQ/callback'
}
DiscordAPIError[10062]: Unknown interaction
at handleErrors (/app/node_modules/@discordjs/rest/dist/index.js:722:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (/app/node_modules/@discordjs/rest/dist/index.js:826:23)
at async _REST.request (/app/node_modules/@discordjs/rest/dist/index.js:1266:22)
at async ChatInputCommandInteraction.deferReply (/app/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:69:5)
at async Object.execute (file:///app/src/commands.js:45:5)
at async Client.<anonymous> (file:///app/src/bot.js:62:3) {
requestBody: { files: undefined, json: { type: 5, data: [Object] } },
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1327467424752341022/aW50ZXJhY3Rpb246MTMyNzQ2NzQyNDc1MjM0MTAyMjo3OTdrdXl0RlhESWZjaFM4d01XRm5keGNaNUFwR3FFY0RRbVp6TG1hemt6Tm8wejdtYW1CSWxqUWZHTDJUT2RTdzlSWEU0bHZHQ0g1aHY2cDJjVmJSczRhU3BCMDNncU03akFESzVnczJNNDNWQTl0ZDZsaHBTWkJOb29yOTZ0bQ/callback'
}
DiscordAPIError[10062]: Unknown interaction
at handleErrors (/app/node_modules/@discordjs/rest/dist/index.js:722:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (/app/node_modules/@discordjs/rest/dist/index.js:826:23)
at async _REST.request (/app/node_modules/@discordjs/rest/dist/index.js:1266:22)
at async ChatInputCommandInteraction.reply (/app/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:111:5)
at async Client.<anonymous> (file:///app/src/bot.js:69:4) {
requestBody: { files: [], json: { type: 4, data: [Object] } },
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1327467424752341022/aW50ZXJhY3Rpb246MTMyNzQ2NzQyNDc1MjM0MTAyMjo3OTdrdXl0RlhESWZjaFM4d01XRm5keGNaNUFwR3FFY0RRbVp6TG1hemt6Tm8wejdtYW1CSWxqUWZHTDJUT2RTdzlSWEU0bHZHQ0g1aHY2cDJjVmJSczRhU3BCMDNncU03akFESzVnczJNNDNWQTl0ZDZsaHBTWkJOb29yOTZ0bQ/callback'
}
20 Replies
d.js toolkit
d.js toolkit2w 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!
d.js docs
d.js docs2w ago
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 responses
NP
NPOP2w ago
@polarwolvinny ❄🌈 i've tried to resolve these things listed but I cant get it to work
treble/luna
treble/luna2w ago
if its unknown even before you reach the defer you either have duplicate listeners/processes or its a host/network issue
NP
NPOP2w ago
it's intermittent, and only happens for some interactions which I can't understand
treble/luna
treble/luna2w ago
sounds like you are taking longer than 3s to send your initial response then
NP
NPOP2w ago
yeah so I have added this
await interaction.deferReply();
await interaction.deferReply();
and i'm using interaction followup to reply
await interaction.followUp({
await interaction.followUp({
im not sure what could be the issue
treble/luna
treble/luna2w ago
if its unknown before it reaches the defer its likely a network or host issue
NP
NPOP2w ago
how would I check this?
treble/luna
treble/luna2w ago
youre gonna have to ask your host for that
NP
NPOP2w ago
Here's the commands.js code, can you see any issues? if not I can share the bot.js
export const bump = {
data: new SlashCommandBuilder()
.setName('xxx')
.setDescription('xxx!'),
async execute(interaction){

const { member } = interaction;
const isOwner = interaction.guild?.ownerId === interaction.member?.user?.id;
if (!interaction.guild) {
await interaction.reply({ content: 'This command can only be used in a server.', ephemeral: true });
return;
}
const isAdmin = member.permissions.has(PermissionsBitField.Flags.Administrator);
const hasManageGuildPermission = member.permissions.has(PermissionsBitField.Flags.ManageGuild);

const hasPermission = isOwner || isAdmin || hasManageGuildPermission;
if(!hasPermission){
interaction.reply({
content: ":bangbang: You must be **owner**, **admin**, or have the '**manage guild**' permission.",
ephemeral: true
})
return;
}

const response = await fetch(`apiurl`, {
method: 'POST',
headers: {
'Content-Type': 'application',
'X-Auth-Key': "apikey"
},
body: JSON.stringify({
guildId: interaction.guild.id
})
});

await interaction.deferReply();

if (response.status !== 200) {
const xErrorMessage = response.headers.get('x-error-message');
const errorMessage = xErrorMessage || 'errormsg';

await interaction.followUp({
content: errorMessage,
ephemeral: true
}).catch(error => {
console.error('Failed to follow up on interaction:', error);
});
return;
}

// Success message
const guildName = interaction.guild.name;
await interaction.followUp({
content: `**${ guildName }** has been successfully xxx!`,
ephemeral: false
});

}
};
export const bump = {
data: new SlashCommandBuilder()
.setName('xxx')
.setDescription('xxx!'),
async execute(interaction){

const { member } = interaction;
const isOwner = interaction.guild?.ownerId === interaction.member?.user?.id;
if (!interaction.guild) {
await interaction.reply({ content: 'This command can only be used in a server.', ephemeral: true });
return;
}
const isAdmin = member.permissions.has(PermissionsBitField.Flags.Administrator);
const hasManageGuildPermission = member.permissions.has(PermissionsBitField.Flags.ManageGuild);

const hasPermission = isOwner || isAdmin || hasManageGuildPermission;
if(!hasPermission){
interaction.reply({
content: ":bangbang: You must be **owner**, **admin**, or have the '**manage guild**' permission.",
ephemeral: true
})
return;
}

const response = await fetch(`apiurl`, {
method: 'POST',
headers: {
'Content-Type': 'application',
'X-Auth-Key': "apikey"
},
body: JSON.stringify({
guildId: interaction.guild.id
})
});

await interaction.deferReply();

if (response.status !== 200) {
const xErrorMessage = response.headers.get('x-error-message');
const errorMessage = xErrorMessage || 'errormsg';

await interaction.followUp({
content: errorMessage,
ephemeral: true
}).catch(error => {
console.error('Failed to follow up on interaction:', error);
});
return;
}

// Success message
const guildName = interaction.guild.name;
await interaction.followUp({
content: `**${ guildName }** has been successfully xxx!`,
ephemeral: false
});

}
};
treble/luna
treble/luna2w ago
Theres your issue That defer has no use at all You have to defer at the top Before doing any async stuff
NP
NPOP2w ago
ah okay, so I need to defer it before async execute?
treble/luna
treble/luna2w ago
no, then interaction wont be defined You have to defer first, before any of your other logic
NP
NPOP2w ago
okay cool, so defering it is the first thing I need to do after async execute?
treble/luna
treble/luna2w ago
Yes Then replace your .reply with editReply
NP
NPOP2w ago
cool thank you! looks to work locally! @treble/luna i've pushed this to prod, however we're still getting these errors
DiscordAPIError[10062]: Unknown interaction
at handleErrors (/app/node_modules/@discordjs/rest/dist/index.js:722:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (/app/node_modules/@discordjs/rest/dist/index.js:826:23)
at async _REST.request (/app/node_modules/@discordjs/rest/dist/index.js:1266:22)
at async ChatInputCommandInteraction.reply (/app/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:111:5)
at async Client.<anonymous> (file:///app/src/bot.js:69:4) {
requestBody: { files: [], json: { type: 4, data: [Object] } },
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1328497333968568391/aW50ZXJhY3Rpb246MTMyODQ5NzMzMzk2ODU2ODM5MTpOZEdGTFBVaDFCdlhMcXRzMEtuRDQ2UVBLRVBOd3ZJejhsZGZrN3NYWFBCaGZxZVhkVUZEeXhrWmx1S0pVR2R2REpMQlFsVmJMdmxOQnpNYjd5Skd6Zk5jSWN2WjRnOHBQblhoUGNJakloWWVtbWJKMzljdXZJQVo5UHhjclNMMw/callback'
}
DiscordAPIError[10062]: Unknown interaction
at handleErrors (/app/node_modules/@discordjs/rest/dist/index.js:722:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (/app/node_modules/@discordjs/rest/dist/index.js:826:23)
at async _REST.request (/app/node_modules/@discordjs/rest/dist/index.js:1266:22)
at async ChatInputCommandInteraction.reply (/app/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:111:5)
at async Client.<anonymous> (file:///app/src/bot.js:69:4) {
requestBody: { files: [], json: { type: 4, data: [Object] } },
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1328497333968568391/aW50ZXJhY3Rpb246MTMyODQ5NzMzMzk2ODU2ODM5MTpOZEdGTFBVaDFCdlhMcXRzMEtuRDQ2UVBLRVBOd3ZJejhsZGZrN3NYWFBCaGZxZVhkVUZEeXhrWmx1S0pVR2R2REpMQlFsVmJMdmxOQnpNYjd5Skd6Zk5jSWN2WjRnOHBQblhoUGNJakloWWVtbWJKMzljdXZJQVo5UHhjclNMMw/callback'
}
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
this needs to be defer reply? the other code I showed you was from commandsjs
treble/luna
treble/luna2w ago
so you are either replying to the same interaction twice, or it took longer than 3s to reply
NP
NPOP2w ago
if it's intermittent issue then it's more likely? and we have that defer in now so i'm not sure
treble/luna
treble/luna2w ago
then indeed you are responding after 3 seconds

Did you find this page helpful?