Skip to main content

Globally configuring guildIds

Previously at Registering Chat Input Commands - guildIds we covered how to register single commands in one or multiple guilds. You may however want to register all your commands in the same guild and not have to repeat the same guildIds over and over again. There are two ways to do this.

First of all your can leverage JavaScript modules. This means simply exporting a constant in another file that holds the guildIds and using that every command. This used to be the recommended way to achieve this, however because many people have asked about registering guildIds globally we have implemented this directly into the framework as well, and that brings us to the second way.

In order to globally configure the guildIds can use ApplicationCommandRegistries.setDefaultGuildIds. This method takes an array of guildIds and will use those for every command that is registered. The ids defined here will only take effect if the command does not have any guildIds defined. This means that you can override the global configuration on a per-command basis by including guildIds in the configuration, and you must remove the guildIds from the command configuration if you want to use the global configuration.

To configure the global guildIds you can do the following:

import { ApplicationCommandRegistries } from '@sapphire/framework';