I’m having trouble with my Discord bot. It’s showing as online in Discord, but I’m getting the error “The application did not respond” when I try to use it. The weird thing is, my old commands (which I’ve deleted) are still visible, but the new ones I’ve added aren’t showing up at all. Here’s a simplified version of my code:
import { Client, GatewayIntentBits } from 'discord.js';
import { readdir } from 'fs/promises';
const bot = new Client({ intents: [GatewayIntentBits.Guilds] });
bot.commands = new Map();
async function loadCommands() {
const files = await readdir('./commands');
for (const file of files) {
if (file.endsWith('.js')) {
const { default: command } = await import(`./commands/${file}`);
bot.commands.set(command.name, command);
}
}
}
bot.once('ready', () => console.log('Bot is ready!'));
bot.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;
const command = bot.commands.get(interaction.commandName);
if (command) {
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply('Oops! Something went wrong.');
}
}
});
await loadCommands();
bot.login(process.env.BOT_TOKEN);
Can anyone help me figure out what’s going wrong? I’m not sure why my new commands aren’t showing up.
It appears your issue stems from not registering the new commands with Discord’s API. While your bot is online and detecting interactions, Discord isn’t aware of the new commands you’ve added.
To resolve this, you’ll need to use Discord’s REST API to register your commands. Create a separate script that sends your command data to Discord. This script should be run whenever you add or modify commands.
Also, ensure your bot has the ‘applications.commands’ scope when you invite it to your server. If you’ve recently added this scope, you may need to reinvite the bot.
Lastly, verify that your command files in ‘./commands’ are structured correctly and exporting the necessary data. Each file should export an object with ‘name’ and ‘execute’ properties at minimum.
If issues persist after trying these steps, consider clearing your Discord cache or waiting a bit, as changes can sometimes take time to propagate across Discord’s systems.
hey sophia, sounds like u might need to register ur new commands with discord API. have u tried using the REST module to send ur command data to discord? also, make sure ur bot has the right permissions in ur server. if nothing works, try restarting ur bot completely. good luck!
I’ve faced similar issues before, and it can be frustrating. From what you’ve shared, it seems the problem might be with command registration. Even if your bot is online, Discord won’t recognize new commands unless they’re properly registered with their API.
One approach that worked for me was to create a separate file for registering commands (for example, ‘deploy-commands.js’) and use the REST module from discord.js to send your command data to Discord. Running this file separately before starting your bot resolved the issue in my case.
Also, double-check your bot’s permissions in your server settings, as insufficient permissions might be causing the problem. If you’ve made significant changes, reinviting the bot with updated scopes could help. Finally, ensure that your command files in the ‘./commands’ directory are structured correctly with the necessary exports.