Slash commands not working

So I have registered my / commands and when I type them, I have a console log to show that it has received the interaction and which one was executed, but it doesn't actually execute the commands. This is my interactionCreate handler
const { Events } = require('discord.js');

module.exports = {
name: Events.InteractionCreate,
async execute(interaction) {
console.log(`Interaction received: ${interaction.commandName}`);
if (interaction.isChatInputCommand()) return;

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

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

try {
await command.execute(interaction);
} catch (e) {
console.error(`Error executing command ${interaction.commandName}: ${e}`);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'An error occurred while executing the command.', ephmeral: true });
} else {
await interaction.reply({ content: 'An error occurred while executing the command.', ephmeral: true });
}
}
},
}
const { Events } = require('discord.js');

module.exports = {
name: Events.InteractionCreate,
async execute(interaction) {
console.log(`Interaction received: ${interaction.commandName}`);
if (interaction.isChatInputCommand()) return;

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

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

try {
await command.execute(interaction);
} catch (e) {
console.error(`Error executing command ${interaction.commandName}: ${e}`);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'An error occurred while executing the command.', ephmeral: true });
} else {
await interaction.reply({ content: 'An error occurred while executing the command.', ephmeral: true });
}
}
},
}
and this is my event handler
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, async (...args) => await event.execute(...args));
}
}
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, async (...args) => await event.execute(...args));
}
}
4 Replies
d.js toolkit
d.js toolkit4w 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!
StellarFr0st
StellarFr0stOP4w ago
The command I am trying to do is user, and this is my user.js command
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('user')
.setDescription('Replies with the user info'),
async execute(interaction) {
console.log(`User info requested by ${interaction.user.username}`);
await interaction.reply(`Your username is **${interaction.user.username}** and you joined the server on **${interaction.member.joinedAt}**`);
},
}
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('user')
.setDescription('Replies with the user info'),
async execute(interaction) {
console.log(`User info requested by ${interaction.user.username}`);
await interaction.reply(`Your username is **${interaction.user.username}** and you joined the server on **${interaction.member.joinedAt}**`);
},
}
My discord.js version is [email protected] and my node version is v20.18.0 I just get The application did not respond in discord when I type the command
treble/luna
treble/luna4w ago
because you return all slash commands interactions
StellarFr0st
StellarFr0stOP4w ago
Oh yeah, stupid mistake!
Want results from more Discord servers?
Add your server