Unknown Interaction. Not sure what the cause is

I'm using openai for chat gpt for general chat. It works sometimes and other times it does not. The error I'm getting is
DiscordAPIError[10062]: Unknown interaction
at handleErrors (E:\My Projects\EstalOBot\node_modules\@discordjs\rest\dist\index.js:722:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (E:\My Projects\EstalOBot\node_modules\@discordjs\rest\dist\index.js:826:23)
at async _REST.request (E:\My Projects\EstalOBot\node_modules\@discordjs\rest\dist\index.js:1266:22)
at async ChatInputCommandInteraction.reply (E:\My Projects\EstalOBot\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:111:5)
at async Object.execute (E:\My Projects\EstalOBot\commands\utility\askgpt.js:38:13)
at async Client.<anonymous> (E:\My Projects\EstalOBot\CrisisBot.js:58:3) {
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/1182356437758918788/aW50ZXJhY3Rpb246MTE4MjM1NjQzNzc1ODkxODc4ODpwOFFIMmtMdFE0Zk54SFZxT0dLNlJRQVJ0b3U3QU4wT3NJQm1KUWw5OVlyeUNHYUpKbDBiSEs0N0FOOUZ5Vjl1aEs4WEhEUkJLcHNHbFozTmNQaERWVXc5cXp1WVBGQjR1eDJndVJxOTY1eGFPcmhjZmNlbEdiMkFNc0o1amVZbw/callback'
}
DiscordAPIError[10062]: Unknown interaction
at handleErrors (E:\My Projects\EstalOBot\node_modules\@discordjs\rest\dist\index.js:722:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (E:\My Projects\EstalOBot\node_modules\@discordjs\rest\dist\index.js:826:23)
at async _REST.request (E:\My Projects\EstalOBot\node_modules\@discordjs\rest\dist\index.js:1266:22)
at async ChatInputCommandInteraction.reply (E:\My Projects\EstalOBot\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:111:5)
at async Object.execute (E:\My Projects\EstalOBot\commands\utility\askgpt.js:38:13)
at async Client.<anonymous> (E:\My Projects\EstalOBot\CrisisBot.js:58:3) {
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/1182356437758918788/aW50ZXJhY3Rpb246MTE4MjM1NjQzNzc1ODkxODc4ODpwOFFIMmtMdFE0Zk54SFZxT0dLNlJRQVJ0b3U3QU4wT3NJQm1KUWw5OVlyeUNHYUpKbDBiSEs0N0FOOUZ5Vjl1aEs4WEhEUkJLcHNHbFozTmNQaERWVXc5cXp1WVBGQjR1eDJndVJxOTY1eGFPcmhjZmNlbEdiMkFNc0o1amVZbw/callback'
}
4 Replies
d.js toolkit
d.js toolkit13mo 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!
Estal
EstalOP13mo ago
Part two.. And the code to actually process the event is
async execute(interaction) {
if (!interaction.isCommand()) return;

const aiQuestion = interaction.options.getString('question');

const openai = new OpenAI({ apiKey: openaiApiKey, engine: gptEngine });

try {
const response = await openai.chat.completions.create({
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: aiQuestion }],
});
const question = `${interaction.user.displayName} asked ${aiQuestion}`;
const answer = response.choices[0].message.content;
console.log(answer);

if (interaction.deferred) {
await interaction.followUp(`${question}\n\n${answer}`);
} else {
await interaction.reply(`${question}\n\n${answer}`);
}

} catch (error) {
await interaction.reply({
content: 'Sorry, I encountered an error while processing your request.',
ephemeral: true,
});
console.error('Error communicating with GPT-3.5:', error.message);
}
}
async execute(interaction) {
if (!interaction.isCommand()) return;

const aiQuestion = interaction.options.getString('question');

const openai = new OpenAI({ apiKey: openaiApiKey, engine: gptEngine });

try {
const response = await openai.chat.completions.create({
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: aiQuestion }],
});
const question = `${interaction.user.displayName} asked ${aiQuestion}`;
const answer = response.choices[0].message.content;
console.log(answer);

if (interaction.deferred) {
await interaction.followUp(`${question}\n\n${answer}`);
} else {
await interaction.reply(`${question}\n\n${answer}`);
}

} catch (error) {
await interaction.reply({
content: 'Sorry, I encountered an error while processing your request.',
ephemeral: true,
});
console.error('Error communicating with GPT-3.5:', error.message);
}
}
What really stumps me is that I'll get the error 1 time, but another the command works fine and the console.log always returns the answer just not sure if I'm handling the interaction wrong or what's going on there.
d.js docs
d.js docs13mo ago
Tag suggestion for @Estal: 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
Estal
EstalOP13mo ago
ah; yeah; sometimes it does take more than three seconds, so tells me that that's probably what I need to read up on. Thanks @Danial 🐝
Want results from more Discord servers?
Add your server