Random "DiscordAPIError[10062]: Unknown Interaction"

i try reproduce the error, but it is so random, I just run the '/user' command several times then it will eventually hit this error. I think it is at 'interaction.deferReply(something)'. monkaS
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
cooldown: 5,
data: new SlashCommandBuilder()
.setName('user')
.setDescription('Provides information about the member.')
.addUserOption(option => option.setName('target')
.setDescription('The member to display information for')
.setRequired(true)),
async execute(interaction) {
console.log('user.js');
await interaction.deferReply({ ephemeral: true });
console.log('user check 1');
const user = await interaction.options.getUser('target', true);
console.log(`This user ${user?.username}, who joined on ${user?.createdAt}.`);
if (!user) {
await interaction.editReply('User not found');
} else {
await interaction.editReply(`This user ${user?.username}, who joined on ${user?.createdAt}.`);
}
},
};
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
cooldown: 5,
data: new SlashCommandBuilder()
.setName('user')
.setDescription('Provides information about the member.')
.addUserOption(option => option.setName('target')
.setDescription('The member to display information for')
.setRequired(true)),
async execute(interaction) {
console.log('user.js');
await interaction.deferReply({ ephemeral: true });
console.log('user check 1');
const user = await interaction.options.getUser('target', true);
console.log(`This user ${user?.username}, who joined on ${user?.createdAt}.`);
if (!user) {
await interaction.editReply('User not found');
} else {
await interaction.editReply(`This user ${user?.username}, who joined on ${user?.createdAt}.`);
}
},
};
No description
11 Replies
d.js toolkit
d.js toolkit11mo 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 staff
treble/luna
treble/luna11mo ago
likely a host / network issue or you're doing some async stuff before reaching the defer
Potato
PotatoOP11mo ago
yes, I run the .execute in this 'InteractionCreate.js' file
const { Events } = require('discord.js');

module.exports = {
name: Events.InteractionCreate,
async execute(interaction) {
if (!interaction.isChatInputCommand()) return;

const command = interaction.client.commands.get(interaction.commandName);
console.log(command.data.name);

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

try {
console.log(`executing /${command.data.name}`);
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 { Events } = require('discord.js');

module.exports = {
name: Events.InteractionCreate,
async execute(interaction) {
if (!interaction.isChatInputCommand()) return;

const command = interaction.client.commands.get(interaction.commandName);
console.log(command.data.name);

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

try {
console.log(`executing /${command.data.name}`);
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 });
}
}
},
};
treble/luna
treble/luna11mo ago
yeah probably host / network issue then
Potato
PotatoOP11mo ago
i run on my own laptop
treble/luna
treble/luna11mo ago
yeah thats probably why
Potato
PotatoOP11mo ago
i just started learning discord.js, following discord.js guide
treble/luna
treble/luna11mo ago
this has nothing to do with djs you just have to get a proper host or get a better connection
Potato
PotatoOP11mo ago
ok I will try put on host to try is there any recommended free server for hosting discord bot?
treble/luna
treble/luna11mo ago
#resources has some though most good hosts are paid
Potato
PotatoOP11mo ago
ok thanks alot!
Want results from more Discord servers?
Add your server