Getting "Unknown interaction" error even with interaction.deferReply()

Hey folks, I am getting a strange error with this code:
class StandingsInteraction {
public async interaction(interaction: TypedCommands['standings']) {
// interaction is ChatInputCommandInteraction
await interaction.deferReply();

const { data, expired } = await standingsCache.getData();

if (!expired) {
return await interaction.editReply({
content: data // data is a string here
});
}

const res = await interaction.editReply({
files: [{
attachment: data, // data is a Buffer here
name: 'la-liga-standings.png'
}]
});

standingsCache.revalidate(res);
}
}
class StandingsInteraction {
public async interaction(interaction: TypedCommands['standings']) {
// interaction is ChatInputCommandInteraction
await interaction.deferReply();

const { data, expired } = await standingsCache.getData();

if (!expired) {
return await interaction.editReply({
content: data // data is a string here
});
}

const res = await interaction.editReply({
files: [{
attachment: data, // data is a Buffer here
name: 'la-liga-standings.png'
}]
});

standingsCache.revalidate(res);
}
}
The problem is that I am randomly getting this error, and I can't figure out why since I am deferring the reply:
DiscordAPIError[10062]: Unknown interaction
at handleErrors (/home/node_modules/@discordjs/rest/dist/index.js:687:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (/home/node_modules/@discordjs/rest/dist/index.js:786:23)
at async _REST.request (/home/node_modules/@discordjs/rest/dist/index.js:1218:22)
at async ChatInputCommandInteraction.deferReply (/home/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:69:5)
at async StandingsInteraction.interaction (file:///home/apps/discord/out/commands/standings.js:5:5)
at async interactionController (file:///home/apps/discord/out/commands/_controller.js:31:7)
at async Client.<anonymous> (file:///home/apps/discord/out/index.js:13:5) {
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/.../callback'
}
DiscordAPIError[10062]: Unknown interaction
at handleErrors (/home/node_modules/@discordjs/rest/dist/index.js:687:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (/home/node_modules/@discordjs/rest/dist/index.js:786:23)
at async _REST.request (/home/node_modules/@discordjs/rest/dist/index.js:1218:22)
at async ChatInputCommandInteraction.deferReply (/home/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:69:5)
at async StandingsInteraction.interaction (file:///home/apps/discord/out/commands/standings.js:5:5)
at async interactionController (file:///home/apps/discord/out/commands/_controller.js:31:7)
at async Client.<anonymous> (file:///home/apps/discord/out/index.js:13:5) {
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/.../callback'
}
I searched online for the problem but without much success.
3 Replies
d.js toolkit
d.js toolkit17mo 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!
Squid
Squid17mo ago
That means that discord is receiving your deferReply() more than 3 seconds after the interaction was created It may just be a network/hardware issue rather than something solvable in your code
decho
dechoOP17mo ago
i understand, but the thing is, i really have nothing that could possibly take 3 seconds until I defer. just a few if statements, but those are never going to take 3 seconds, not even 3 milliseconds. before the class method gets called i mean, there is nothing that would take so long i actually can't remember. the error seemed super random and i can't seem to be able to reproduce it right now, yesterday it was happening semi-frequently. I think this mostly occurs around startup times so maybe it's not that big of a deal. If it becomes a problem I will have to look into it again, but at the moment I don't want to spend hours on this. seems to be similar to this but there is no resolution available: https://github.com/discordjs/discord.js/issues/7005 it might be taking more than 3 seconds, but only after the deferReply this problem is on a local high end machine, ryzen 9 7900 pc so it's not slow
// index.ts (interaction event start (1))
discord.on(Events.InteractionCreate, async (interaction) => {
if (interaction.isChatInputCommand()) {
await interactionController(interaction);
}
});
// controller.ts (controller (2))
export async function interactionController(interaction: ChatInputCommandInteraction) {
try {
if (isTyped.command(interaction, 'standings')) {
await standingssInteraction.interaction(interaction);
}
} catch (error) {
if (error instanceof DiscordError) {
await error.report(interaction);
}
else {
console.error(error);
}
}
}
// standings.ts (interaction handler (3))
class StandingsInteraction {
public async interaction(interaction: TypedCommands['standings']) {
await interaction.deferReply();

const { data, expired } = await standingsCache.getData();

if (!expired) {
return await interaction.editReply({
content: data
});
}

const res = await interaction.editReply({
files: [{
attachment: data,
name: 'la-liga-standings.png'
}]
});

standingsCache.revalidate(res);
}
}
// index.ts (interaction event start (1))
discord.on(Events.InteractionCreate, async (interaction) => {
if (interaction.isChatInputCommand()) {
await interactionController(interaction);
}
});
// controller.ts (controller (2))
export async function interactionController(interaction: ChatInputCommandInteraction) {
try {
if (isTyped.command(interaction, 'standings')) {
await standingssInteraction.interaction(interaction);
}
} catch (error) {
if (error instanceof DiscordError) {
await error.report(interaction);
}
else {
console.error(error);
}
}
}
// standings.ts (interaction handler (3))
class StandingsInteraction {
public async interaction(interaction: TypedCommands['standings']) {
await interaction.deferReply();

const { data, expired } = await standingsCache.getData();

if (!expired) {
return await interaction.editReply({
content: data
});
}

const res = await interaction.editReply({
files: [{
attachment: data,
name: 'la-liga-standings.png'
}]
});

standingsCache.revalidate(res);
}
}
that's my entire code so all you have before the defer is these two if statements:
// 1
if (interaction.isChatInputCommand()) {
await interactionController(interaction);
}
// 2
if (isTyped.command(interaction, 'standings')) {
await standingssInteraction.interaction(interaction);
}
// 1
if (interaction.isChatInputCommand()) {
await interactionController(interaction);
}
// 2
if (isTyped.command(interaction, 'standings')) {
await standingssInteraction.interaction(interaction);
}
yeah i was thinking the same between receiving the initial interaction request and then the discord servers receiving my bot response >3 seconds discord could be laggy once in a while, might be related to that, but either way, thanks for trying to help, don't think there is much i can do about this
Want results from more Discord servers?
Add your server