how to handle "unknown interaction" error

try {
return await interaction.reply(...);
} catch (error) {
if ((error as Error).message.includes("Unknown interaction")) {
return await interaction.reply(...);
{
console.error(Error);
return null;
}
}
try {
return await interaction.reply(...);
} catch (error) {
if ((error as Error).message.includes("Unknown interaction")) {
return await interaction.reply(...);
{
console.error(Error);
return null;
}
}
if the "unknown interaction" error occurs, should i try to reply to the interaction again or wut? i think the error occurs when the user is lagging
7 Replies
d.js toolkit
d.js toolkit2mo 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!
Amgelo
Amgelo2mo ago
should i try to reply to the interaction again or wut?
no, you can't do anything with that interaction anymore as it's now "Unknown" for discord (it doesn't exist anymore), you should just log it or maybe send a message to the channel saying something failed if that works for you
i think the error occurs when the user is lagging
most of the time it actually happens because of your bot lagging in some way (either the bot itself or network lag) and not being able to respond to the interaction before it expires, but there can be other reasons as stated below
d.js docs
d.js docs2mo 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
Amgelo
Amgelo2mo ago
as noted, to avoid it defer or reply as early as possible, but if even a defer isn't arriving on time then something could be wrong in your bot or your network
potsu
potsu2mo ago
i see, but would i be able to access the channel object if the interaction is unknown?
Amgelo
Amgelo2mo ago
yeah the variable doesn't update in real time or anything you just can't do anything on discord with the interaction itself, eg replying, deferring but you can still do stuff with the channel, user, etc
potsu
potsu2mo ago
aight thanks