Unknown interaction

Hello i keep getting the "unknown interaction" error like 7 out of 10 times every time i run a slash command or use any component i'll share my InteractionCreate event and one of my slash commands:
const { Events } = require('discord.js');

module.exports = {
name: Events.InteractionCreate,

eventCallback: async (interaction, client) => {
if (interaction.isChatInputCommand()) {
for (const command of interaction.client.commands) {
if (command.name === interaction.commandName) {
await command.callback(interaction)
}
}
}



else {
const ticketHandler = require("./ticketInteraction.js");
await ticketHandler(interaction);
}
}
};
const { Events } = require('discord.js');

module.exports = {
name: Events.InteractionCreate,

eventCallback: async (interaction, client) => {
if (interaction.isChatInputCommand()) {
for (const command of interaction.client.commands) {
if (command.name === interaction.commandName) {
await command.callback(interaction)
}
}
}



else {
const ticketHandler = require("./ticketInteraction.js");
await ticketHandler(interaction);
}
}
};
ping.js:
module.exports = {
name: 'ping',
description: 'Replies with Pong!',

callback: async (interaction) => {
await interaction.deferReply();

const reply = await interaction.fetchReply();

const ping = reply.createdTimestamp - interaction.createdTimestamp;

interaction.editReply(`Pong! Client ${ping}ms | Websocket: ${interaction.client.ws.ping}ms`)
}
};
module.exports = {
name: 'ping',
description: 'Replies with Pong!',

callback: async (interaction) => {
await interaction.deferReply();

const reply = await interaction.fetchReply();

const ping = reply.createdTimestamp - interaction.createdTimestamp;

interaction.editReply(`Pong! Client ${ping}ms | Websocket: ${interaction.client.ws.ping}ms`)
}
};
i can share my event handler or more code if needed
9 Replies
d.js toolkit
d.js toolkit•4d ago
Youcef
YoucefOP•4d ago
discord.js -> 14.21.0 node -> v22.17.1
duck
duck•4d ago
what actually happens when you receive the error? does your bot respond anyways, or do you receive "The application did not respond" in client (or something to that effect)?
Youcef
YoucefOP•4d ago
i receive "The application did not respond" error
duck
duck•4d ago
then sounds like your bot just isn't responding to the interaction fast enough, even with deferReply being the first thing you do in the shown command this can happen for a variety of reasons, usually due to your host's network/resources side note deferReply has a withResponse option for which deferReply will resolve in an InteractionCallbackResponse with this you can access <InteractionCallbackResponse>.resource.message without needing to fetchReply afterwards
Youcef
YoucefOP•4d ago
well i do have a really slow internet but iam not sure if that's the issue because i have been working on the bot for the past 2 weeks and i just started getting this error about 2 days ago and it's honestly driving me crazy ah i see, thanks
duck
duck•4d ago
regardless of the reason, the issue is that your bot isn't responding within 3 seconds if you don't believe it to be your network, it's still up to you to determine why your bot isn't reaching deferReply fast enough
Youcef
YoucefOP•4d ago
okay i'll do more debugging okay i think it's probably and issue with my commands handler or events handlers, because i put the ping command directly inside index.js like this and i no longer get the error:
const { Client, GatewayIntentBits} = require('discord.js');
const mongoose = require('mongoose')
const { token, databaseKey } = require('../config.json');
const eventHandler = require('./handlers/eventHandler');
const commandHandler = require('./handlers/commandHandler');

const { DisTube } = require('distube');
const { YtDlpPlugin } = require('@distube/yt-dlp');


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


client.distube = new DisTube(client, {
emitNewSongOnly: true,
emitAddSongWhenCreatingQueue: false,
emitAddListWhenCreatingQueue: false,
plugins: [new YtDlpPlugin()]
});



(async () => {
try {
await mongoose.connect(databaseKey);
console.log("Connected to the database.");

client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});

client.on('interactionCreate', async (interaction) => {
if (interaction.commandName === 'ping') {
await interaction.deferReply();

const reply = await interaction.fetchReply();

const ping = reply.createdTimestamp - interaction.createdTimestamp;

interaction.editReply(`Pong! Client ${ping}ms | Websocket: ${interaction.client.ws.ping}ms`)
}
});

//commandHandler(client);
//eventHandler(client);
client.login(token);

} catch (error) {
console.log(`[ERROR WHILE CONNECTING TO THE DATABASE]: ${error}`);
}
})();
const { Client, GatewayIntentBits} = require('discord.js');
const mongoose = require('mongoose')
const { token, databaseKey } = require('../config.json');
const eventHandler = require('./handlers/eventHandler');
const commandHandler = require('./handlers/commandHandler');

const { DisTube } = require('distube');
const { YtDlpPlugin } = require('@distube/yt-dlp');


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


client.distube = new DisTube(client, {
emitNewSongOnly: true,
emitAddSongWhenCreatingQueue: false,
emitAddListWhenCreatingQueue: false,
plugins: [new YtDlpPlugin()]
});



(async () => {
try {
await mongoose.connect(databaseKey);
console.log("Connected to the database.");

client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});

client.on('interactionCreate', async (interaction) => {
if (interaction.commandName === 'ping') {
await interaction.deferReply();

const reply = await interaction.fetchReply();

const ping = reply.createdTimestamp - interaction.createdTimestamp;

interaction.editReply(`Pong! Client ${ping}ms | Websocket: ${interaction.client.ws.ping}ms`)
}
});

//commandHandler(client);
//eventHandler(client);
client.login(token);

} catch (error) {
console.log(`[ERROR WHILE CONNECTING TO THE DATABASE]: ${error}`);
}
})();
what 😭 okay iam still a beginner tho 😭 oh you mean DisTube? i just searched about it and i found that it violates tos... i had no idea...
d.js toolkit
d.js toolkit•3d ago
The thread owner has marked this issue as solved.

Did you find this page helpful?