Unknown Interaction - @discordjs/core

I'm working on a bot that handles interactions via a webhook url, and am processing them in AWS Lambda. I have everything set up properly, including responding to the ping interaction, but no matter what I do, I keep getting an Unknown Interaction error.
const mainHandler = async (
_event: APIGatewayProxyEvent,
context: InteractionContext
): Promise<APIGatewayProxyResult> => {
const rest = new REST({ version: '10' }).setToken(context.clientSecret);

const interaction = context.interaction;

const webhooksAPI = new WebhooksAPI(rest);
const interactionsAPI = new InteractionsAPI(rest, webhooksAPI);

if (interaction.type === InteractionType.Ping) {
return {
statusCode: 200,
body: JSON.stringify({ type: InteractionType.Ping })
};
}

const response = await interactionsAPI.reply(interaction.id, interaction.token, { content: 'Pong!' });

return {
statusCode: 200,
body: JSON.stringify(response)
};
};
const mainHandler = async (
_event: APIGatewayProxyEvent,
context: InteractionContext
): Promise<APIGatewayProxyResult> => {
const rest = new REST({ version: '10' }).setToken(context.clientSecret);

const interaction = context.interaction;

const webhooksAPI = new WebhooksAPI(rest);
const interactionsAPI = new InteractionsAPI(rest, webhooksAPI);

if (interaction.type === InteractionType.Ping) {
return {
statusCode: 200,
body: JSON.stringify({ type: InteractionType.Ping })
};
}

const response = await interactionsAPI.reply(interaction.id, interaction.token, { content: 'Pong!' });

return {
statusCode: 200,
body: JSON.stringify(response)
};
};
In the above, I'm creating the apis from a custom context being passed in, and attempting to just respond to any non-ping interaction with 'Pong!', but every time the function is invoked, I get the following error:
{
"errorType": "DiscordAPIError[10062]",
"errorMessage": "Unknown interaction",
"code": 10062,
"requestBody": {
"json": {
"type": 4,
"data": {
"content": "Pong!"
}
}
},
"rawError": {
"message": "Unknown interaction",
"code": 10062
},
"status": 404,
"method": "POST",
"url": "https://discord.com/api/v10/interactions/.../callback",
"stack": [
"DiscordAPIError[10062]: Unknown interaction",
" at handleErrors (/var/task/node_modules/@discordjs/rest/dist/index.js:687:13)",
" at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
" at async BurstHandler.runRequest (/var/task/node_modules/@discordjs/rest/dist/index.js:786:23)",
" at async _REST.request (/var/task/node_modules/@discordjs/rest/dist/index.js:1218:22)",
" at async InteractionsAPI.reply (/var/task/node_modules/@discordjs/core/dist/index.js:1602:5)",
" at async mainHandler (/var/task/index.js:18:22)",
" at async Runtime.handler (/var/task/middleware/verify.js:36:12)"
]
}
{
"errorType": "DiscordAPIError[10062]",
"errorMessage": "Unknown interaction",
"code": 10062,
"requestBody": {
"json": {
"type": 4,
"data": {
"content": "Pong!"
}
}
},
"rawError": {
"message": "Unknown interaction",
"code": 10062
},
"status": 404,
"method": "POST",
"url": "https://discord.com/api/v10/interactions/.../callback",
"stack": [
"DiscordAPIError[10062]: Unknown interaction",
" at handleErrors (/var/task/node_modules/@discordjs/rest/dist/index.js:687:13)",
" at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
" at async BurstHandler.runRequest (/var/task/node_modules/@discordjs/rest/dist/index.js:786:23)",
" at async _REST.request (/var/task/node_modules/@discordjs/rest/dist/index.js:1218:22)",
" at async InteractionsAPI.reply (/var/task/node_modules/@discordjs/core/dist/index.js:1602:5)",
" at async mainHandler (/var/task/index.js:18:22)",
" at async Runtime.handler (/var/task/middleware/verify.js:36:12)"
]
}
Any idea what's going on?
8 Replies
d.js toolkit
d.js toolkit10mo 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!
_Rob
_Rob10mo ago
It's worth noting, the ping interaction verifies successfully.
monbrey
monbrey10mo ago
Whats your performance like? You only have 3 seconds to complete a response to an interaction
_Rob
_Rob10mo ago
Hmm, that's a good point. If an interaction times out, does it not exist anymore?
monbrey
monbrey10mo ago
Essentially yes, theres a 3 seconds period n which Discord needs it to be acknowledged as successful, either defer to reply Then the token remains active for 15 minutes for edits and followUps If the lambda needs to spin up every time it might be a little slow
_Rob
_Rob10mo ago
I'll have to dig into cloud trail or something to see what the response time is That's probably it. I just hit the bot with 5 subsequent interactions, and the first 3 failed, but the last 2 didn't Thanks for narrowing it down for me. I'll have to see what I can do to get spinup time to be lower Instead of posting a new question, I want to follow up here. I'm having a similar issue from before, but now I'm getting an unknown webhook error.
const mainHandler = async (
_event: APIGatewayProxyEvent,
context: InteractionContext
): Promise<APIGatewayProxyResult> => {
const rest = new REST({ version: '10' }).setToken(context.clientSecret);

const interaction = context.interaction;

const webhooksAPI = new WebhooksAPI(rest);
const interactionsAPI = new InteractionsAPI(rest, webhooksAPI);

await interactionsAPI.defer(interaction.id, interaction.token);

await new Promise((resolve) => setTimeout(resolve, 5000));

const response = await interactionsAPI.editReply(interaction.id, interaction.token, { content: 'Pong!' });

return {
statusCode: 200,
body: JSON.stringify(response)
};
};
const mainHandler = async (
_event: APIGatewayProxyEvent,
context: InteractionContext
): Promise<APIGatewayProxyResult> => {
const rest = new REST({ version: '10' }).setToken(context.clientSecret);

const interaction = context.interaction;

const webhooksAPI = new WebhooksAPI(rest);
const interactionsAPI = new InteractionsAPI(rest, webhooksAPI);

await interactionsAPI.defer(interaction.id, interaction.token);

await new Promise((resolve) => setTimeout(resolve, 5000));

const response = await interactionsAPI.editReply(interaction.id, interaction.token, { content: 'Pong!' });

return {
statusCode: 200,
body: JSON.stringify(response)
};
};
The defer works perfectly fine, but after the timeout, when I try to edit the reply is when I get the error I've also tried interactions.followUp(...), but have the same result
duck
duck10mo ago
editReply and all the other methods that use /webhooks endpoints take the application id as the webhook id, not the interaction id
_Rob
_Rob10mo ago
Thanks! That fixed it.