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

Below async execute?

Yes, that’s correct.

this is dumb but double check if it’s processing the command and replies in under 15 minutes

because from the error the interaction token probablyexpired or the interaction wasn’t procsesed within the right timeframe
interaction tokens are valid for 15 minutes so maybe the token expired if it isn’t processing the command and replying back in under 15 minutes

 Attempting to connect to the database

(node:13632) [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:13632) [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
Logged in as RankCraftX1 (5735671213)
 
                        ____________MONGOOSE____________

                            CONNECTED TO THE DATABASE

                        ____________MONGOOSE____________


Successfully registered (2) commands globally.
node:events:496
      throw er; // Unhandled 'error' event
      ^

DiscordAPIError[10062]: Unknown interaction
    at handleErrors (C:\Users\Admin\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\Admin\OneDrive\Desktop\RankCraft\node_modules\@discordjs\rest\dist\index.js:826:23)
    at async _REST.request (C:\Users\Admin\OneDrive\Desktop\RankCraft\node_modules\@discordjs\rest\dist\index.js:1266:22)
    at async ChatInputCommandInteraction.reply (C:\Users\Admin\OneDrive\Desktop\RankCraft\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:111:5)
    at async Object.execute (C:\Users\Admin\OneDrive\Desktop\RankCraft\commands\setup.js:21:48)
    at async Client.<anonymous> (C:\Users\Admin\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: "You don't have access as this command is broken!",
        tts: false,
        nonce: undefined,
        embeds: undefined,
        components: undefined,
        username: undefined,
        avatar_url: undefined,
        allowed_mentions: undefined,
        flags: undefined,
        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

Send me your latest setup js

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 isBrokenCommandAccess = member ? member.roles.cache.get('1225429932302270624') : false
            if (!isBrokenCommandAccess) return
            await interaction.deferReply();
            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.editReply({ content: ' ', ephemeral: true, embeds: [AlreadyRegistered ]})
            };
                
            if (ServerAlreadySettedUp) {
                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] })
            }
        },    
};

Ok, give me a second to inspect the 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 isBrokenCommandAccess = member ? member.roles.cache.get('1225429932302270624') : false
            if (!isBrokenCommandAccess) return
            await interaction.deferReply();
            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.');
            await interaction.reply({ content: 'Checking', ephemeral: true })
            if (AlreadyRegisteredGroup) {               
                return await interaction.editReply({ content: ' ', ephemeral: true, embeds: [AlreadyRegistered ]})
            } else {
                if (ServerAlreadySettedUp) {
                    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] })
            }
        },    
};
1 Like

@RobloxSupp515 Try this code

What did you change?

I added a main reply to the code and I added 2 edits based on the result.

Wait, Now it won’t see if its already taken, (Group)

Well I cant spend more time right now but have a look at it and fix the structure and it should work.

1 Like

I can’t figure it out,

Okay so im no gonna give you a simple base of what needs to be done, kind of in a todo format and this should help you.

Setup code
First, you need to import all required modules (as you seem to have already done). After this, you’ll need to make the SlashCommandBuilder() structure with the options needed.

Second,
Second you will need to, DIRECTLY UNDER, your async execute function, put ‘interaction.deferReply()’. This informs discord that you may need longer than 3 seconds to run this command, so you can edit embeds, check code, etc.

Third,
Third you will need to have an if() statement that checks if the user running the code has the required roles/permissions to run the command.

Fourth,
Fourth you need to find the server in the MongoDB. Example:

const s = await Schema.findOne({ id: interaction.guild.id })

Then you’ll need to check if the server exists with the proper setup. If it does, then continue on, if it doesn’t then it needs to create a new server/database instance with that ID and then update it with the Group ID and all other needed information.

Fifth,
Then you need to make it check for a certain string of characters in the user’s profile. You can use noblox.js or create your own function for it. An example function could look like:

function getUserById(userId) {
    return axios.get(`https://api.roblox.com/users/${userId}`)
        .then(response => response.data)
        .catch(error => {
            console.error("Error retrieving user data:", error);
            return null;
        });
}```
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.