Discord bot appears online but slash commands not working and showing 'application did not respond' error

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?

Had this exact issue and it drove me crazy for hours. Your bot code’s fine for handling interactions, but Discord doesn’t know your commands exist yet. You need a separate script that registers them with the REST API - something like rest.put(Routes.applicationCommands(clientId), { body: commands }). Those old deleted commands sticking around? Classic Discord cache weirdness. They’ll disappear eventually or just reload Discord to force it. Run the registration script every time you change commands.

hey, you might’ve missed registering the slash cmds with Discord’s API. without that, new commands won’t show. check for a deploy-commands.js file or smth similar to manage the registration through the REST API.

The ‘application did not respond’ error often indicates that your bot received the interaction but failed to reply in a timely manner, hitting Discord’s timeout. Review your command files to ensure each one contains a proper run function, utilizing either interaction.reply() or interaction.deferReply() to handle longer tasks. Additionally, confirm that the command files correctly export the name and run properties; any discrepancies here can lead to the error you’re experiencing.