My discord Bot keeps breaking: DiscordAPIError[10062]: Unknown interaction

Hello! So basically my embed for my upcoming ranking bot has an embed error,

(ERROR)

RankCraft#7766 is ready to assist people with ranking
 Attempting to connect to the database

(node:9424) [MONGODB DRIVER] Warning: useNewUrlParser is a deprecated option: useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version
(Use `node --trace-warnings ...` to show where the warning was created)
(node:9424) [MONGODB DRIVER] Warning: useUnifiedTopology is a deprecated option: useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version
Successfully registered (2) commands globally.
 
                        ____________MONGOOSE____________

                            CONNECTED TO THE DATABASE

                        ____________MONGOOSE____________


Logged in as RankCraftX1 (5735671213)
node:events:496
      throw er; // Unhandled 'error' event
      ^

DiscordAPIError[10062]: Unknown interaction
    at handleErrors (C:\Users\Ethan\OneDrive\Desktop\RankCraft\node_modules\@discordjs\rest\dist\index.js:722:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async BurstHandler.runRequest (C:\Users\Ethan\OneDrive\Desktop\RankCraft\node_modules\@discordjs\rest\dist\index.js:826:23)
    at async _REST.request (C:\Users\Ethan\OneDrive\Desktop\RankCraft\node_modules\@discordjs\rest\dist\index.js:1266:22)
    at async ChatInputCommandInteraction.reply (C:\Users\Ethan\OneDrive\Desktop\RankCraft\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:111:5)
    at async Object.execute (C:\Users\Ethan\OneDrive\Desktop\RankCraft\commands\setup.js:36:17)
    at async Client.<anonymous> (C:\Users\Ethan\OneDrive\Desktop\RankCraft\index.js:109:2)
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: [],
    json: {
      type: 4,
      data: {
        content: ' ',
        tts: false,
        nonce: undefined,
        embeds: [
          {
            color: 15548997,
            title: 'Taken Group',
            description: 'This group id has already been setted up, Think this is a problem? Go open a ticket in our server.'
          }
        ],
        components: undefined,
        username: undefined,
        avatar_url: undefined,
        allowed_mentions: undefined,
        flags: 64,
        message_reference: undefined,
        attachments: undefined,
        sticker_ids: undefined,
        thread_name: undefined
      }
    }
  },
  rawError: { message: 'Unknown interaction', code: 10062 },
  code: 10062,
  status: 404,
  method: 'POST',
  url: '(NOT GIVING YOU MY URL)'
}

Node.js v20.11.1

(My Code)

const { PermissionFlagsBits, EmbedBuilder, Embed, PermissionsBitField, ActionRowBuilder, ButtonBuilder, ButtonStyle, Guild } = require('discord.js');
const noblox = require('noblox.js')
const { SlashCommandBuilder, messageLink } = require('@discordjs/builders')
const setup = require('../Schema/setup');
const supportGuildID = '1209961261538738177'
const supportGuildIDChannel = '1224398128921317386'

module.exports = {
	data: new SlashCommandBuilder()
		.setName('setup')
		.setDescription('Setup your bot.')
        .addNumberOption(option => option.setName('groupid').setDescription('Enter a valid group ID to use.').setRequired(true)),
        async execute(interaction, client) {
			if(!interaction.guild) return await interaction.reply('Please use this in a server!')
            const { options, guild } = interaction;

            const supportGuild = client.guilds.cache.get('1209961261538738177')
            const member = supportGuild.members.cache.get(interaction.user.id)
            const isEarlyAccess = member ? member.roles.cache.get('1224360424749924494') : false
            const GroupID = options.getNumber('groupid');

            const ServerAlreadySettedUp = await setup.findOne({ GuildID: guild.id })
            const AlreadyRegisteredGroup = await setup.findOne({ Groupid: GroupID })

            const AlreadyRegistered = new EmbedBuilder()
                .setColor('Red')
                .setTitle('Taken Group')
                .setDescription('This group id has already been setted up, Think this is a problem? Go open a ticket in our server.');
    
                const AlreadySettedUp = new EmbedBuilder()
                .setColor('Red')
                .setTitle('Setted up')
                .setDescription('This server is already setted up, If you want to want to remove the server from linking to the group please open a ticket in our server.');

            if (AlreadyRegisteredGroup) {
                await interaction.reply({ content: ' ', ephemeral: true, embeds: [AlreadyRegistered ]})
                return;
            };
                
            if (ServerAlreadySettedUp) {
                await interaction.reply({ content: ' ', ephemeral: true, embeds: [AlreadySettedUp ]})
                return;
            };

            const RequestedBotEmbed = new EmbedBuilder()
            .setColor('Orange')
            .setTitle('Bot Requested')
            .setDescription('A guild requested a bot to be in their group!')
            .addFields({ name: 'Guild ID', value: `${interaction.guild.id}` }, { name: 'Sender ID', value: `${interaction.user.id}` })
            .setTimestamp();

            if (isEarlyAccess) {
    
            } else {
                const ForbiddenEmbed = new EmbedBuilder()
                .setColor('Red')
                .setTitle('Not Whitelisted')
                .setDescription('This command is currently wip and you are trying to use it, please wait for it to release, \n\n\n\(If you want the early access please pay 500 robux into our tshirt')
                await interaction.reply({ embeds: [ForbiddenEmbed] })
            }
        },    
};

What do you not understand about the error?

interaction.reply in AlreadyRegisteredGRoup and ServerAlreadySettedUp

What exactly is the error and what causes it to happen? Does it happen after running the /setup command or what causes it?

It is exactly the interaction.reply in AlreadyRegisteredGroup and ServerAlreadySettedUp, It happens after I run the /setup (It runs through a embed to confirm) and then it returns an error

Try return await interaction.reply etc and not await interaction.reply
return;

node:events:496
      throw er; // Unhandled 'error' event
      ^

DiscordAPIError[10062]: Unknown interaction
    at handleErrors (C:\Users\Ethan\OneDrive\Desktop\RankCraft\node_modules\@discordjs\rest\dist\index.js:722:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async BurstHandler.runRequest (C:\Users\Ethan\OneDrive\Desktop\RankCraft\node_modules\@discordjs\rest\dist\index.js:826:23)
    at async _REST.request (C:\Users\Ethan\OneDrive\Desktop\RankCraft\node_modules\@discordjs\rest\dist\index.js:1266:22)
    at async ChatInputCommandInteraction.reply (C:\Users\Ethan\OneDrive\Desktop\RankCraft\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:111:5)
    at async Object.execute (C:\Users\Ethan\OneDrive\Desktop\RankCraft\commands\setup.js:36:24)
    at async Client.<anonymous> (C:\Users\Ethan\OneDrive\Desktop\RankCraft\index.js:109:2)
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: [],
    json: {
      type: 4,
      data: {
        content: ' ',
        tts: false,
        nonce: undefined,
        embeds: [
          {
            color: 15548997,
            title: 'Taken Group',
            description: 'This group id has already been setted up, Think this is a problem? Go open a ticket in our server.'
          }
        ],
        components: undefined,
        username: undefined,
        avatar_url: undefined,
        allowed_mentions: undefined,
        flags: 64,
        message_reference: undefined,
        attachments: undefined,
        sticker_ids: undefined,
        thread_name: undefined
      }
    }
  },
  rawError: { message: 'Unknown interaction', code: 10062 },
  code: 10062,
  status: 404,
  method: 'POST',
  url: 'NOT GIVING YOU MY URL'
}

Node.js v20.11.1

Gives me this now.

This seems to be an issue with your coding logic. The error is clear, I am taking a look at the code and error in your original topic.

DiscordAPIError[10062]: Unknown interaction


The error is coming from line 36:

await interaction.reply({ content: ' ', ephemeral: true, embeds: [AlreadyRegistered] })

An unkown Interaction error is when you attempt to work with any interaction that no longer exists, it’s important to note that Discord invalidates if the bot does not acknowledge the interaction within 3 seconds

I think to get around this you can use deferred responses.

Source: Issues with the Discord API: Unknown interaction discord.js - Stack Overflow


P.S:

I would like to note you have a couple of typos in your script that make no sense, the corrected version of your Description would be:

This group id has already been set up, Think this is a problem? Go open a ticket on our server.

1 Like
node:events:496
      throw er; // Unhandled 'error' event
      ^

DiscordAPIError[10062]: Unknown interaction
    at handleErrors (C:\Users\Ethan\OneDrive\Desktop\RankCraft\node_modules\@discordjs\rest\dist\index.js:722:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async BurstHandler.runRequest (C:\Users\Ethan\OneDrive\Desktop\RankCraft\node_modules\@discordjs\rest\dist\index.js:826:23)
    at async _REST.request (C:\Users\Ethan\OneDrive\Desktop\RankCraft\node_modules\@discordjs\rest\dist\index.js:1266:22)
    at async ChatInputCommandInteraction.deferReply (C:\Users\Ethan\OneDrive\Desktop\RankCraft\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:69:5)
    at async Object.execute (C:\Users\Ethan\OneDrive\Desktop\RankCraft\commands\setup.js:36:24)
    at async Client.<anonymous> (C:\Users\Ethan\OneDrive\Desktop\RankCraft\index.js:109:2)
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: 64 } } },
  rawError: { message: 'Unknown interaction', code: 10062 },
  code: 10062,
  status: 404,
  method: 'POST',
  url: 'NOT GIVING YOU MY URL
}

Node.js v20.11.1

We’ll need to see your updated code, I’ve never used discord.js before, so this is a new experience for me too.

const { PermissionFlagsBits, EmbedBuilder, Embed, PermissionsBitField, ActionRowBuilder, ButtonBuilder, ButtonStyle, Guild } = require('discord.js');
const noblox = require('noblox.js')
const { SlashCommandBuilder, messageLink } = require('@discordjs/builders')
const setup = require('../Schema/setup');
const supportGuildID = '1209961261538738177'
const supportGuildIDChannel = '1224398128921317386'

module.exports = {
	data: new SlashCommandBuilder()
		.setName('setup')
		.setDescription('Setup your bot.')
        .addNumberOption(option => option.setName('groupid').setDescription('Enter a valid group ID to use.').setRequired(true)),
        async execute(interaction, client) {
			if(!interaction.guild) return await interaction.reply('Please use this in a server!')
            const { options, guild } = interaction;

            const supportGuild = client.guilds.cache.get('1209961261538738177')
            const member = supportGuild.members.cache.get(interaction.user.id)
            const isEarlyAccess = member ? member.roles.cache.get('1224360424749924494') : false
            const GroupID = options.getNumber('groupid');

            const ServerAlreadySettedUp = await setup.findOne({ GuildID: guild.id })
            const AlreadyRegisteredGroup = await setup.findOne({ Groupid: GroupID })

            const AlreadyRegistered = new EmbedBuilder()
                .setColor('Red')
                .setTitle('Taken Group')
                .setDescription('This group id has already been set up, Think this is a problem? Go open a ticket on our server.');
    
                const AlreadySettedUp = new EmbedBuilder()
                .setColor('Red')
                .setTitle('Setted up')
                .setDescription('This server is already setted up, If you want to want to remove the server from linking to the group please open a ticket in our server.');

            if (AlreadyRegisteredGroup) {
                return await interaction.deferReply({ content: ' ', ephemeral: true, embeds: [AlreadyRegistered ]})
            };
                
            if (ServerAlreadySettedUp) {
                return await interaction.deferReply({ content: ' ', ephemeral: true, embeds: [AlreadySettedUp ]})
            };

            const RequestedBotEmbed = new EmbedBuilder()
            .setColor('Orange')
            .setTitle('Bot Requested')
            .setDescription('A guild requested a bot to be in their group!')
            .addFields({ name: 'Guild ID', value: `${interaction.guild.id}` }, { name: 'Sender ID', value: `${interaction.user.id}` })
            .setTimestamp();

            if (isEarlyAccess) {
    
            } else {
                const ForbiddenEmbed = new EmbedBuilder()
                .setColor('Red')
                .setTitle('Not Whitelisted')
                .setDescription('This command is currently wip and you are trying to use it, please wait for it to release, \n\n\n\(If you want the early access please pay 500 robux into our tshirt')
                await interaction.reply({ embeds: [ForbiddenEmbed] })
            }
        },    
};

In the example they use it like this:

		await interaction.deferReply();
		await wait(4_000);
		await interaction.editReply('Pong!');

You don’t seem to be using it incorrectly, you need to deferRely first, then you need to edit the reply.

It still returns the same error

But on the
interaction.deferReply();
this time.

Because you have to defer the reply first.

What do you mean? Mind explaing a little bit mroe?

You have to defer the response, before you edit it.

I did defer the response.

Show me your updated code.

const { PermissionFlagsBits, EmbedBuilder, Embed, PermissionsBitField, ActionRowBuilder, ButtonBuilder, ButtonStyle, Guild } = require('discord.js');
const noblox = require('noblox.js')
const { SlashCommandBuilder, messageLink } = require('@discordjs/builders')
const setup = require('../Schema/setup');
const supportGuildID = '1209961261538738177'
const supportGuildIDChannel = '1224398128921317386'

module.exports = {
	data: new SlashCommandBuilder()
		.setName('setup')
		.setDescription('Setup your bot.')
        .addNumberOption(option => option.setName('groupid').setDescription('Enter a valid group ID to use.').setRequired(true)),
        async execute(interaction, client) {
			if(!interaction.guild) return await interaction.reply('Please use this in a server!')
            const { options, guild } = interaction;

            const supportGuild = client.guilds.cache.get('1209961261538738177')
            const member = supportGuild.members.cache.get(interaction.user.id)
            const isEarlyAccess = member ? member.roles.cache.get('1224360424749924494') : false
            const GroupID = options.getNumber('groupid');

            const ServerAlreadySettedUp = await setup.findOne({ GuildID: guild.id })
            const AlreadyRegisteredGroup = await setup.findOne({ Groupid: GroupID })

            const AlreadyRegistered = new EmbedBuilder()
                .setColor('Red')
                .setTitle('Taken Group')
                .setDescription('This group id has already been set up, Think this is a problem? Go open a ticket on our server.');
    
                const AlreadySettedUp = new EmbedBuilder()
                .setColor('Red')
                .setTitle('Setted up')
                .setDescription('This server is already setted up, If you want to want to remove the server from linking to the group please open a ticket in our server.');

            if (AlreadyRegisteredGroup) {
                await interaction.deferReply();
                await wait(4_000);
                return await interaction.editReply({ content: ' ', ephemeral: true, embeds: [AlreadyRegistered ]})
            };
                
            if (ServerAlreadySettedUp) {
                await interaction.deferReply();
                await wait(4_000);
                return await interaction.editReply({ content: ' ', ephemeral: true, embeds: [AlreadySettedUp ]})
            };

            const RequestedBotEmbed = new EmbedBuilder()
            .setColor('Orange')
            .setTitle('Bot Requested')
            .setDescription('A guild requested a bot to be in their group!')
            .addFields({ name: 'Guild ID', value: `${interaction.guild.id}` }, { name: 'Sender ID', value: `${interaction.user.id}` })
            .setTimestamp();

            if (isEarlyAccess) {
    
            } else {
                const ForbiddenEmbed = new EmbedBuilder()
                .setColor('Red')
                .setTitle('Not Whitelisted')
                .setDescription('This command is currently wip and you are trying to use it, please wait for it to release, \n\n\n\(If you want the early access please pay 500 robux into our tshirt')
                await interaction.reply({ embeds: [ForbiddenEmbed] })
            }
        },    
};

Try making defer the first thing that executes.