Unknown Interaction

DiscordAPIError[10062]: Unknown interaction at handleErrors (C:\Users\Anwender\Desktop\Hansis Manager\node_modules@discordjs\rest\dist\index.js:687:13) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async BurstHandler.runRequest (C:\Users\Anwender\Desktop\Hansis Manager\node_modules@discordjs\rest\dist\index.js:786:23) at async _REST.request (C:\Users\Anwender\Desktop\Hansis Manager\node_modules@discordjs\rest\dist\index.js:1218:22) at async ChatInputCommandInteraction.reply (C:\Users\Anwender\Desktop\Hansis Manager\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:111:5) at async Object.execute (C:\Users\Anwender\Desktop\Hansis Manager\commands\moderation\ping.js:8:3) at async Object.execute (C:\Users\Anwender\Desktop\Hansis Manager\events\interactionCreate.js:16:4) { requestBody: { files: [], json: { type: 4, data: [Object] } }, rawError: { message: 'Unknown interaction', code: 10062 }, code: 10062, status: 404, method: 'POST',
17 Replies
d.js toolkit
d.js toolkit13mo 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
Jonas
JonasOP13mo ago
Despite an error being registered, the command is executed.
d.js docs
d.js docs13mo 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
probablyraging
probablyraging13mo ago
Likely one of the reasons above, can't help much more unless you show code
Jonas
JonasOP13mo ago
user.js:
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('user')
.setDescription('Provides information about the user.'),
async execute(interaction) {
// interaction.user is the object representing the User who ran the command
// interaction.member is the GuildMember object, which represents the user in the specific guild
await interaction.reply(`This command was run by ${interaction.user.username}, who joined on ${interaction.member.joinedAt}.`);
},
};
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('user')
.setDescription('Provides information about the user.'),
async execute(interaction) {
// interaction.user is the object representing the User who ran the command
// interaction.member is the GuildMember object, which represents the user in the specific guild
await interaction.reply(`This command was run by ${interaction.user.username}, who joined on ${interaction.member.joinedAt}.`);
},
};
index.js:
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');

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

client.commands = new Collection();

client.once(Events.ClientReady, () => {
console.log(`Ready! Logged in as ${client.user.tag}`);
client.user.setPresence({ activities: [{ name: 'Minecraft' }], status: 'idle' });
});

const commandsPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(commandsPath);

for (const folder of commandFolders) {
const folderPath = path.join(commandsPath, folder);
const commandFiles = fs.readdirSync(folderPath).filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
const filePath = path.join(folderPath, file);
const command = require(filePath);

if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');

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

client.commands = new Collection();

client.once(Events.ClientReady, () => {
console.log(`Ready! Logged in as ${client.user.tag}`);
client.user.setPresence({ activities: [{ name: 'Minecraft' }], status: 'idle' });
});

const commandsPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(commandsPath);

for (const folder of commandFolders) {
const folderPath = path.join(commandsPath, folder);
const commandFiles = fs.readdirSync(folderPath).filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
const filePath = path.join(folderPath, file);
const command = require(filePath);

if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;

const command = client.commands.get(interaction.commandName);

if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}

try {
await command.execute(interaction);
} catch (error) {
console.error(error);

if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});

const eventsPath = path.join(__dirname, 'events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));

for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
const event = require(filePath);

if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}

client.login(token);
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;

const command = client.commands.get(interaction.commandName);

if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}

try {
await command.execute(interaction);
} catch (error) {
console.error(error);

if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});

const eventsPath = path.join(__dirname, 'events');
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));

for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
const event = require(filePath);

if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}

client.login(token);
Which script do you need so that you can help me?#
probablyraging
probablyraging13mo ago
Well that would depends when the error occurs, does it happen when you run the users.js file or?
Jonas
JonasOP13mo ago
Yes
Jonas
JonasOP13mo ago
Yes.. But i have no idea
probablyraging
probablyraging13mo ago
What did you try, show me the code changes
Jonas
JonasOP13mo ago
I have no idea what I should change in the code.
treble/luna
treble/luna13mo ago
why do you have an event handler but still have a regular listener
Jonas
JonasOP13mo ago
I took it from the guide.
treble/luna
treble/luna13mo ago
i'm pretty sure you just managed to register the even twice the even handler does not tell you to put your listeners inside it your listeners should be separate files
Jonas
JonasOP13mo ago
ok That means?
treble/luna
treble/luna13mo ago
that you should have your event listeners in separate files
Jonas
JonasOP13mo ago
Okay It works! Thank you very much! :D
Want results from more Discord servers?
Add your server