DiscordAPIError[10062]

Hi everyone, I have a question about the DiscordAPIError[10062]. I understand this error is related to interaction timing out in my program, not resolving the interaction within 3 seconds. To mitigate this, I attempted to defer the reply to extend the interaction timeout to 15 minutes. However, when I send the deferred interaction and await it, the process breaks, possibly because the defer reply isn't sent fast enough (at least that's my theory). About a week ago, I switched to a local DNS server, but I suspect it's not configured correctly because my requests are unusually slow. Even when switching to public DNS servers like 1.1.1.1 or 8.8.8.8, the issue persists. Essentially, my question is whether the problem lies with my local setup or if there might be another underlying issue. i will list my code in the comments because of the character limit where I've added extensive logging statements to aid in debugging (yes, I'm aware it's not the best practice):
14 Replies
d.js toolkit
d.js toolkit7mo 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!
feelfeel2008
feelfeel2008OP7mo ago
const {Client, IntentsBitField, Message,} = require("discord.js")
require('dotenv').config();
const resolve_command = require("./interaction-handler.js")


const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
]});


module.exports = client

client.on("ready", () => {
console.log("Bot is ready!");
});

client.on("interactionCreate" , async (interaction) => {
console.log("i got the command")
console.log(interaction.id)
await interaction.deferReply()
console.log("deferdf reply")

if (!interaction.isChatInputCommand()) return;

resolve_command(interaction)

console.log("i have been finished")

await interaction.editReply("hi i gueesss")

console.log("sent the command")




})

client.login(process.env.DISCORD_BOT_TOKEN)
console.log("logged in!")
const {Client, IntentsBitField, Message,} = require("discord.js")
require('dotenv').config();
const resolve_command = require("./interaction-handler.js")


const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.MessageContent,
]});


module.exports = client

client.on("ready", () => {
console.log("Bot is ready!");
});

client.on("interactionCreate" , async (interaction) => {
console.log("i got the command")
console.log(interaction.id)
await interaction.deferReply()
console.log("deferdf reply")

if (!interaction.isChatInputCommand()) return;

resolve_command(interaction)

console.log("i have been finished")

await interaction.editReply("hi i gueesss")

console.log("sent the command")




})

client.login(process.env.DISCORD_BOT_TOKEN)
console.log("logged in!")
And here's the error I'm encountering: logged in! Bot is ready! i got the command 1252684797470445661 node:events:496 throw er; // Unhandled 'error' event ^ DiscordAPIError[10062]: Unknown interaction at handleErrors (/home/felix/projects/basic_Discord_Bot/node_modules/@discordjs/rest/dist/index.js:730:13) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async BurstHandler.runRequest (/home/felix/projects/basic_Discord_Bot/node_modules/@discordjs/rest/dist/index.js:835:23) at async _REST.request (/home/felix/projects/basic_Discord_Bot/node_modules/@discordjs/rest/dist/index.js:1278:22) at async ChatInputCommandInteraction.deferReply (/home/felix/projects/basic_Discord_Bot/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:71:5) at async Client.<anonymous> (/home/felix/projects/basic_Discord_Bot/src/app.js:24:5) Emitted 'error' event on Client instance at: at emitUnhandledRejectionOrErr (node:events:401:10) at process.processTicksAndRejections (node:internal/process/task_queues:84:21) { requestBody: { files: undefined, json: { type: 5, data: { flags: undefined } } }, rawError: { message: 'Unknown interaction', code: 10062 }, code: 10062, status: 404, method: 'POST', url: 'https://discord.com/api/v10/interactions/1252684797470445661/aW50ZXJhY3Rpb246MTI1MjY4NDc5NzQ3MDQ0NTY2MTp5UkVhWFNqeHNieFZqQUhMakFPTWNiUGtFS2RQc3Z6OWlSUms1aDB1OFFLa1ZnMUpZUDFKbHFmeU9HMlBuajBUNWhPTzV3NlZnQTd2bTRqUHdtTXhzT3NRYnIzeDdPeFBoOGdZc2VuVUhLdEZFeEJQSUcwdms1SlpUNTFKVlgxWg/callback' } Node.js v20.12.2
monbrey
monbrey7mo ago
Yeah, unfortunately this means there may still be some very slow handling happening. To confirm, does the command get deferred in Discord at all?
feelfeel2008
feelfeel2008OP7mo ago
no the bot never defers the command it does get to the point where it does defer it but i think it takes to long resulting in the bot crashing when the deferd response reaches discord.
monbrey
monbrey7mo ago
Yeah, well I dont see any issues with this code Other than maybe client being exported from index, but it shouldnt cause this issue
feelfeel2008
feelfeel2008OP7mo ago
ill maybe try it on another computer and see if that helps. thanks for confirming.
monbrey
monbrey7mo ago
Where does client get re-used, in interaction-handler.js?
feelfeel2008
feelfeel2008OP7mo ago
it does not get used at all. just added that to expand to other files when needed. is this a bad practice?
monbrey
monbrey7mo ago
kinda yeah, you risk having circular references. index imports a file, which imports client from index, which imports the file, which imports client.... You generally should pass it to other things as a function parameter, or use the one attached to discord.js objects like interaction.client
feelfeel2008
feelfeel2008OP7mo ago
i see. thanks!
chmod
chmod7mo ago
I may be facing the same thing so just joining the thread. Do you know how it breaks, does the defer time out? (rest default is 15 seconds)
feelfeel2008
feelfeel2008OP7mo ago
The default for a rest discord interaction is 3 seconds, that’s why if your processing something that takes longer then 3 seconds you use interaction.deferreply() that gets you an extra 15 minutes to process. My problem (and maybe yours) is that my internet is so slow that I can even send the deferreply to discord in time.
chmod
chmod7mo ago
Rest default timeout is a bit different than interaction timeout, so when you deferReply initially, does the msg actually get deferred on discord? Does the bot show up as "thinking..." while your code on the other hand breaks?
feelfeel2008
feelfeel2008OP7mo ago
Apologies for the confusion. The issue arises when I send the deferred reply message to Discord; a three-second interaction timeout occurs before Discord receives the deferred reply. Consequently, instead of showing "thinking," the application displays "the application did not respond." This indicates that Discord never received the deferred reply due to the timeout.
Want results from more Discord servers?
Add your server