Server & Global commands

By default, your commands will be registered globally. This means it will be available to all servers your bot is in. However, this may not be something you want, as globally registered commands can take a while to be pushed or removed from Discord. You especially don't want this during development.

To ensure your commands are registered on a specific server, add the testServer property to DiscordHandler like this:

index.js
const { Client, IntentsBitField } = require('discord.js');
const { CommandHandler } = require('djs-commander');
const path = require('path');

const client = new Client({
  intents: [IntentsBitField.Flags.Guilds],
});

new CommandHandler({
  client,
  commandsPath: path.join(__dirname, 'commands'),
  testServer: 'TEST_SERVER_ID', // This ensures your commands are guild-based
});

client.login('YOUR_TOKEN_HERE');

It's important to note that guild(server)-based commands can only be registered if your bot is in the specified server.

When you're taking your bot public and want it to have its commands registered globally, then remove the testServer property.

Last updated