I keep getting Unknown Interaction errors in my console

I have lots of people using my bot each day and there seems to always be Unknown Interaction errors when people use commands. I haven't been able to recreate this issue myself and it doesn't even happen 100% of the time (sometimes that code runs fine, and other times it throws that error). I don't really see what the problem is in my code. Refer to the image, the circled file is what this code is..
const { somethingWentWrong, noRedditCategories } = require("./commonMessages");
const { formatEmbedImage, formatRedditImage } = require("./formatDiscordImages");
const { retrieveImage } = require("./imageDatabaseHandler");
const { makeRedditRequest } = require("./makeRedditRequest");
const { fetchOrUpdateMember } = require("./queryDB");
const settings = require("../settings/clients/hentaicord.json");
const { memberData } = require("../mongoose");

async function retrieveHandler(interaction, type, category, isRepeat) {

let dbMember;
try { dbMember = await memberData.findOneAndUpdate({ discord_id: interaction.user.id }, {}, { upsert: true, new: true }); }
catch (error) { return console.error(error); }

let replyObject;
if(type === "reddit") {
if(!await noRedditCategories(interaction)) return; //does a premium status check before proceeding

let random_media = await makeRedditRequest(category);
if(random_media.success === false) return await somethingWentWrong(interaction);
random_media = random_media.data.data;

let format = await formatRedditImage(type, category);
if(format.success === false) return await somethingWentWrong(interaction);
format = format.data;

replyObject = { content: random_media.url, components: [ format.button ] };
}

else {
if(category === "random") {
let available_categories = settings.categories[type].filter(x => x !== "random");
category = available_categories[Math.floor(Math.random() * available_categories.length)];
}
let randomImage = await retrieveImage(type.toLowerCase(), category.toLowerCase());
if(randomImage.success == false) return await somethingWentWrong(interaction);
randomImage = randomImage.image;

let format = await formatEmbedImage(interaction, type, category, randomImage);
if(format.success === false) return await somethingWentWrong(interaction);
format = format.data;

replyObject = { embeds: [format.embed], components: [format.button] };
};

if(isRepeat === true && dbMember.toggles.replace_images === true) {
await interaction.update(replyObject).catch(console.error);
}

else {
await interaction.reply(replyObject).catch(console.error);
}

}


module.exports.retrieveHandler = retrieveHandler;
const { somethingWentWrong, noRedditCategories } = require("./commonMessages");
const { formatEmbedImage, formatRedditImage } = require("./formatDiscordImages");
const { retrieveImage } = require("./imageDatabaseHandler");
const { makeRedditRequest } = require("./makeRedditRequest");
const { fetchOrUpdateMember } = require("./queryDB");
const settings = require("../settings/clients/hentaicord.json");
const { memberData } = require("../mongoose");

async function retrieveHandler(interaction, type, category, isRepeat) {

let dbMember;
try { dbMember = await memberData.findOneAndUpdate({ discord_id: interaction.user.id }, {}, { upsert: true, new: true }); }
catch (error) { return console.error(error); }

let replyObject;
if(type === "reddit") {
if(!await noRedditCategories(interaction)) return; //does a premium status check before proceeding

let random_media = await makeRedditRequest(category);
if(random_media.success === false) return await somethingWentWrong(interaction);
random_media = random_media.data.data;

let format = await formatRedditImage(type, category);
if(format.success === false) return await somethingWentWrong(interaction);
format = format.data;

replyObject = { content: random_media.url, components: [ format.button ] };
}

else {
if(category === "random") {
let available_categories = settings.categories[type].filter(x => x !== "random");
category = available_categories[Math.floor(Math.random() * available_categories.length)];
}
let randomImage = await retrieveImage(type.toLowerCase(), category.toLowerCase());
if(randomImage.success == false) return await somethingWentWrong(interaction);
randomImage = randomImage.image;

let format = await formatEmbedImage(interaction, type, category, randomImage);
if(format.success === false) return await somethingWentWrong(interaction);
format = format.data;

replyObject = { embeds: [format.embed], components: [format.button] };
};

if(isRepeat === true && dbMember.toggles.replace_images === true) {
await interaction.update(replyObject).catch(console.error);
}

else {
await interaction.reply(replyObject).catch(console.error);
}

}


module.exports.retrieveHandler = retrieveHandler;
The line console is referring to is the:
else {
await interaction.reply(replyObject).catch(console.error);
}
else {
await interaction.reply(replyObject).catch(console.error);
}
1 Reply
d.js toolkit
d.js toolkit12mo 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! - Marked as resolved by OP
Want results from more Discord servers?
Add your server