Slash Command Registration Issues in Discord.js Bot Development

Hey everyone! I’m working on my first Discord bot using discord.js and I’ve hit a roadblock. My bot responds to regular messages just fine, but I can’t get slash commands to register properly. I followed the official docs but something isn’t working right.

I double checked my bot token and application ID multiple times. The weird part is that there are no error messages in the console at all. The registration script runs without any issues but the commands don’t show up in Discord.

import { REST, Routes } from 'discord.js';

const BOT_TOKEN = 'my_bot_token_here';
const APPLICATION_ID = 'my_app_id_here';

const slashCommands = [
  {
    name: 'hello',
    description: 'Bot responds with a greeting message',
  },
];

const restClient = new REST({ version: '10' }).setToken(BOT_TOKEN);

try {
  console.log('Beginning slash command registration process.');

  await restClient.put(Routes.applicationCommands(APPLICATION_ID), { body: slashCommands });

  console.log('Slash command registration completed successfully.');
} catch (err) {
  console.error(err);
}

Any ideas what might be going wrong here?

Had the same issue a few months ago. You’re probably missing the command handler in your main bot file. Registering commands is only half the battle - you need to listen for and respond to interactions too. Make sure you’ve got an interactionCreate event listener handling slash command execution. Without it, Discord won’t know your bot can process commands even though they’re registered. Your registration code looks good, but double-check you’re using client.on('interactionCreate', async interaction => {...}) in your main script. Also make sure your bot has admin permissions or at least Use Slash Commands in your test server.

Had this exact problem when I started with slash commands. You’re probably registering global commands - those take up to an hour to show up across Discord’s servers. That’s why you’re not getting errors but can’t see the commands. Switch to guild-specific commands for testing. Change Routes.applicationCommands(APPLICATION_ID) to Routes.applicationGuildCommands(APPLICATION_ID, GUILD_ID) using your test server’s ID. Guild commands appear instantly. Also check if your bot has the applications.commands scope. If you only invited it with the bot scope, you’ll need to re-invite it with both scopes from the Developer Portal.

check your bot perms in server settings. commands can register fine but won’t show up without proper perms. go to server settings > integrations > [your bot name] and make sure slash commands are enabled. this tripped me up when i was starting out too lol

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.