My Discord bot connects successfully and shows as online, but I’m having issues with slash commands. When I try to use any command, I get an error message saying ‘The application did not respond’. The weird thing is that old commands I deleted are still visible, but the new ones I created don’t appear at all.
const { Client, Collection, GatewayIntentBits } = require('discord.js');
const path = require('path');
const fs = require('fs');
require('dotenv').config();
const bot = new Client({
intents: [GatewayIntentBits.Guilds]
});
bot.slashCommands = new Collection();
const commandFolder = path.join(__dirname, 'commands');
const cmdFiles = fs.readdirSync(commandFolder).filter(f => f.endsWith('.js'));
for (const fileName of cmdFiles) {
const cmdPath = path.join(commandFolder, fileName);
const cmdModule = require(cmdPath);
bot.slashCommands.set(cmdModule.name, cmdModule);
}
bot.on('ready', () => {
console.log(`Bot ${bot.user.username} is now online!`);
});
bot.on('interactionCreate', async (interaction) => {
if (!interaction.isChatInputCommand()) return;
const cmd = bot.slashCommands.get(interaction.commandName);
if (!cmd) return;
try {
await cmd.run(interaction);
} catch (err) {
console.log(err);
await interaction.reply({ content: 'Command failed to execute.', ephemeral: true });
}
});
bot.login(process.env.BOT_TOKEN);
Any ideas on what might be causing this problem?