DiscordAPIError[10062]: Unknown interaction randomly popped up

I’m trying to make a discord bot. for a skyblock server, using the commands it will show for example farming level, etc. this code use to work just fine, the next day when I started it I got this error following. Note: it only breaks in the Farming function that I created I did a dungeon’s functions and slash command and it worked just fine.

Error : DiscordAPIError[10062]: Unknown interaction at handleErrors (C:Usersyy3OneDriveDisktopSkyblockbotnode_modules@discordjsrestdistindex.js:730:13) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async BurstHandler.runRequest (C:Usersyy3OneDriveDisktopSkyblockbotnode_modules@discordjsrestdistindex.js:835:23) at async _REST.request (C:Usersyy3OneDriveDisktopSkyblockbotnode_modules@discordjsrestdistindex.js:1278:22) at async ChatInputCommandInteraction.deferReply (C:Usersyy3OneDriveDisktopSkyblockbotnode_modulesdiscord.jssrcstructuresinterfacesInteractionResponses.js:71:5) at async Client.<anonymous> (C:Usersyy3OneDriveDisktopSkyblockbotsrcindex.js:307:9) Emitted 'error' event on Client instance at: at emitUnhandledRejectionOrErr (node:events:402: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/1271726598881804370/aW50ZXJhY3Rpb246MTI3MTcyNjU5ODg4MTgwNDM3MDpoRFlWN1hwODUxVGNLY21lRnk1NWh4UEVOT0tYQllLblZZR0Z5WXJ0eHdZSExiVUlDR0w0Qmc1ak5uUjRvZ3p2a2xpVzRDd3RNb0hDODFlUFhwWVVQNGZOSURGQjlGNnBVMzVlbEpkZzl4MHZLU1VXSVhQT01iUkl3NHd1c1JGRg/callback' }

require('dotenv').config();
const { UserFlags } = require('discord-api-types/v9');
const {Client, GatewayIntentBits, EmbedBuilder, PermissionsBitField, Permissions, SlashCommandBuilder, Events} = require('discord.js');
const { MongoClient } = require('mongodb');


const uri = "mongodb://localhost:27017/";
const dbName = "skyblock";
const collectionUsers = "profiles";

const mongoclient = new MongoClient(uri, { useNewURLParser: true, useUnifiedTopology: true });


// Connecting-Reading Database Collections.
mongoclient.connect()
    .then(() => {
        console.log('Connected to MongoDB');

        const db = mongoclient.db(dbName);

        return db.listCollections().toArray();
    })
    .then(collections => {
        let count = 0
        console.log('Collections in database:');
        collections.forEach(collection => {
            count = count + 1
        });
        console.log(`${count} Collections Loaded`)
    });




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


function Mapping(n, mapping) {
    let count = 0;
    for (let i = 0; i < mapping.length; i++) {
        n -= mapping[i];
        if (n < 0) {
            return count;
        }
        count = i + 1;
    }
    return count;
}

function capitalizeUsername(username) {
    if (!username) return ''; // Handle empty or undefined input
    return username.charAt(0).toUpperCase() + username.slice(1).toLowerCase();
}

function catchFarmingMapping(Level) {

    farmingMapping = [50, 125, 200, 300, 500, 750, 1000, 1500, 2000, 3500, 5000, 7500, 10000, 15000, 20000, 30000, 50000, 75000, 100000, 200000, 300000, 400000, 500000, 600000, 700000, 800000, 900000, 1000000, 1100000, 1200000, 1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1900000, 2000000, 2100000, 2200000, 2300000, 2400000, 2500000, 2600000, 2750000, 2900000, 3100000, 3400000, 3700000, 4000000, 4300000, 4600000, 4900000, 5200000, 5500000, 5800000, 6100000, 6400000, 6700000, 7000000];

    const Farming = Mapping(Level, farmingMapping);
    console.log(Farming)
    return Farming;
}

function catchCatacombMapping(Level) {

    dungeonmapping = [ 50, 75, 110, 160, 230, 330, 470, 670, 950, 1340, 1890, 2665, 3760, 5260, 7380, 10300, 14400, 20000, 27600, 38000, 52500, 71500, 97000, 132000, 180000, 243000, 328000, 445000, 600000, 800000, 1065000, 1410000, 1900000, 2500000, 3300000, 4300000, 5600000, 7200000, 9200000, 12000000, 15000000, 19000000, 24000000, 30000000, 38000000, 48000000, 60000000, 75000000, 93000000, 116250000 ]

    const Catacomb = Mapping(Level, dungeonmapping);
    console.log(Catacomb);
    return Catacomb;
}

async function catchDungeonLevel(User) {
    const database = mongoclient.db('skyblock');
    const usersCollection = database.collection('users');
    const profileMemCollection = database.collection('profile_members');

    const user = await usersCollection.findOne({ lowercase_name: User });

    if (!user) {
        console.log('User not found');
        return null;
    }

    const activeProfile = user.active_profile;
    console.log('Active Profile:', activeProfile);

    const profile = await profileMemCollection.findOne({ profile_id: activeProfile });

    if (!profile) {
        console.log('Profile not found');
        return null;
    }

    const CatacombExperience = profile.data?.dungeons?.dungeon_types?.CATACOMBS?.experience;

    console.log(CatacombExperience);

    if (CatacombExperience !== undefined) {
        const DungeonLevel = Math.floor(CatacombExperience);
        return DungeonLevel;
    } else {
        console.log('Farming experience not found');
        return null;
    }
}

async function catchFarmingMedals(User) {

    const database = mongoclient.db('skyblock');
    const usersCollection = database.collection('users');
    const profileMemCollection = database.collection('profile_members');

    const filter = { lowercase_name: User };
    const user = await usersCollection.findOne(filter);

    console.log(filter)
    activeProfile = user.active_profile
    console.log(activeProfile)

    if (User) {

        const filter = { profile_id: activeProfile };
        const Profile = await profileMemCollection.findOne(filter);
        
        if (Profile) {
            Gold = Profile.data?.farming?.gold
            Silver = Profile.data?.farming?.silver
            Bronze = Profile.data?.farming?.bronze

            console.log(`Gold ${Gold}, Silver ${Silver}, Bronze ${Bronze}`)
        }
    }

}

async function catchFarmingLevel(User) {
    const database = mongoclient.db('skyblock');
    const usersCollection = database.collection('users');
    const profileMemCollection = database.collection('profile_members');

    const user = await usersCollection.findOne({ lowercase_name: User });

    if (!user) {
        console.log('User not found');
        return null;
    }

    const activeProfile = user.active_profile;
    console.log('Active Profile:', activeProfile);

    const profile = await profileMemCollection.findOne({ profile_id: activeProfile });

    if (!profile) {
        console.log('Profile not found');
        return null;
    }

    const farmingExperience = profile.data?.experience_skill_farming;

    if (farmingExperience !== undefined) {
        const farmingLevel = Math.floor(farmingExperience);
        return farmingLevel;
    } else {
        console.log('Farming experience not found');
        return null;
    }
}

async function catchFarmingContests(User) {

    const database = mongoclient.db('skyblock');
    const usersCollection = database.collection('users');
    const profileMemCollection = database.collection('profile_members');

    const filter = { lowercase_name: User };
    const user = await usersCollection.findOne(filter);

    console.log(filter)
    activeProfile = user.active_profile
    console.log(activeProfile)

    if (User) {

        const filter = { profile_id: activeProfile };
        const Profile = await profileMemCollection.findOne(filter);
        
        if (Profile) {
            Contests = Profile.data?.farming?.contests;

            if (Profile.data?.farming?.contests && typeof Profile.data?.farming?.contests === 'object') {
                const numberOfContests = Object.keys(Profile.data?.farming?.contests).length;
                console.log(`Number of contests: ${numberOfContests}`);
                return numberOfContests;
            } else {
                console.log('Contests data is either undefined or not an object');
                return null;
            }
        }
    }

}

client.on(Events.ClientReady, (e) => {
    console.log(`✅ ${e.user.tag} is ready!`);

    const farming = new SlashCommandBuilder()
    .setName ('farming')
    .setDescription ('View a players farming statistics!')
    .addStringOption(option =>
        option
        .setName('username')
        .setDescription('Minecraft Username')
        .setRequired(true)
    )

    const support = new SlashCommandBuilder()
    .setName ('support')
    .setDescription ('Supporting fakepixel')

    const dungeons = new SlashCommandBuilder()
    .setName ('dungeons')
    .setDescription ('View dungeon stats')
    .addStringOption(option =>
        option
        .setName('username')
        .setDescription('Minecraft Username')
        .setRequired(true)
    )

    client.application.commands.create(farming);
    client.application.commands.create(support);
    client.application.commands.create(dungeons);

});

client.on('interactionCreate', async (interaction) => {
    if(!interaction.isChatInputCommand()) return;

    if(interaction.commandName==='dungeons') {
        const username = interaction.options.getString('username');

        if(username) {
            const Username = username
            const username_lowercase = Username.toLowerCase();

            try {

                const FetchDungeonExperience = await catchDungeonLevel(username_lowercase);
                const FetchDungeonLevel = await catchCatacombMapping(FetchDungeonExperience);
                console.log(FetchDungeonExperience);
                console.log(FetchDungeonLevel);

                interaction.reply(`Catacomb :${FetchDungeonLevel}`);

            } catch (error) {

                console.error('Error handling Dungeons command:', error);
                interaction.reply('Please provide a valid username to fetch Dungeons details.');

            }
        }

    } else {
        interaction.reply('Please provide a valid username to fetch farming details.');
    }
})


client.on('interactionCreate', async (interaction) => {
    if(!interaction.isChatInputCommand()) return;

    if(interaction.commandName==='support') {

        const supportEmbed = new EmbedBuilder()
        .setTitle(`Fakepixel Support`)
        .setDescription(`Fakepixel is a thriving Minecraft server that thrives on the support of its community. By supporting Fakepixel, you help keep the server running and enable us to continually provide exciting updates and new features. As a token of our gratitude, supporters receive a range of exclusive perks that enhance your in-game experience.`)
        .setColor('#347deb')
        .addFields({
            name: 'Features:',
            value: `• **Cool Prefix & Chat Customization** - Stand out with a unique prefix and a custom chat color.
            • **Custom Commands** - Gain access to special command like /fly, /vanish to enhance your gameplay.
            • **Support the Server** - Show your dedication and help Fakepixel grow stronger.
            • **Discord Perks** - Share media files in the Discord server and connect with the community.
            • **Exclusive Beta Tester Access** - Be among the first to try out new features and content before anyone else.
            `,
            inline: true
        })
        .setImage('https://i.imgur.com/8ObuWiL.png')
        .setFooter({text: 'by @Dyamonic', iconURL: 'https://i.imgur.com/dVdkH9y.gif'})

        interaction.reply({embeds: [supportEmbed]});
    }
})


client.on('interactionCreate', async (interaction) => {
    if(!interaction.isChatInputCommand()) return;

    if(interaction.commandName==='farming') {
        await interaction.deferReply({})
        const username = interaction.options.getString('username');

        if(username) {
            const username_lowercase = username.toLowerCase();
            const Username_Capitial = capitalizeUsername(Username);

            try {

            const FetchFarmingLevel = await catchFarmingLevel(username_lowercase);
            const FetchFarmingMapping = await catchFarmingMapping(FetchFarmingLevel);
            const FetchFarmingMedals = await catchFarmingMedals(username_lowercase);
            const FetchFarmingContests = await catchFarmingContests(username_lowercase);


            await interaction.editReply(`
                Username : ${Username_Capitial}
                Farming : ${FetchFarmingMapping}
                Gold : ${Gold}
                Silver : ${Silver}
                Bronze : ${Bronze}
                Contests : ${FetchFarmingContests}`);

            //const farmingEmbed = new EmbedBuilder()
            //.setTitle(`${Username_Capitial}'s Farming Skill on Profile`)
            //.setDescription(`<:Iron_hoe:1268545041735876704> Farming: **${FetchFarmingMapping}**
            //    <:Farming_Contest:1268545029509742623> Contests: **${FetchFarmingContests}**`)
            //.setColor('#347deb')
            //.setThumbnail(`https://visage.surgeplay.com/full/${username_lowercase}`)
            //.addFields({
            //    name: 'Medals',
            //    value: `<:Gold_Ingot:1268544990510972949> Gold: ${Gold}
            //    <:Iron_Ingot:1268545007422275645>  Silver: ${Silver}
            //    <:Clay_Brick:1268545018688180276> Bronze: ${Bronze}`,
            //    inline: true
            //})
            //.setFooter({text: 'by @Dyamonic | Support by using /support', iconURL: 'https://i.imgur.com/dVdkH9y.gif'})
    
            //interaction.reply({embeds: [farmingEmbed]});

            } catch (error) {

                console.error('Error handling farming command:', error);
                interaction.reply('Please provide a valid username to fetch farming details.');

            }

        }
        else {
            interaction.reply('Please provide a valid username to fetch farming details.');
        }
    }
})

client.login(process.env.TOKEN);