Skip to main content

Routing existing Application Commands to a Command

If you want to route existing or multiple other application commands to one of your commands, or just don't want Sapphire handling application command registering for you (😢), you can provide the ids or names (not recommended) of application commands to a command's application command registry and we'll properly route invocations to the command.

Most users will probably be fine using the idHints option of registerChatInputCommand or registerContextmenuCommand, see the section in Registering Chat Input Commands for more details.

info

As a friendly reminder, Discord manages "Application Command Objects" on their end for each of your application commands. Whenever your bot registers a new application command with Discord, they create and store a new object like this:

{
"id": "1223334444555554444",
"application_id": "...",
// ...
"name": "foo",
"description": "bar!"
}

When we say "...Provide X from Application Command Objects..." below, what we mean is to copy the field X from the Application Command Object(s) corresponding to the application command(s) you want Sapphire to route to your command.

Application Command Registry Methods​

addChatInputCommandIds(...)​

Provide id(s) from Application Command Objects that identify the application commands you want to route to this command.

warning

Whenever the addContextMenuCommandIds method is called with an invalid id (we expect a string that can be turned into a BigInt), then it will ALWAYS log a warning in the console. No, this cannot be turned off.

addChatInputCommandNames(...)​

Provide names from Application Command Objects that identify the application commands you want to route to this command.

addContextMenuCommandIds(...)​

Same as addChatInputCommandIds but for context menu commands

addContextMenuCommandNames(...)​

Same as addChatInputCommandNames but for context menu commands

Adding from inside a command​

const { Command } = require('@sapphire/framework');

class UwUCommand extends Command {
registerApplicationCommands(registry) {
// Adding a name
// NOT RECOMMENDED. Use the id methods with ids instead.
registry.addChatInputCommandNames('uwu');

// Adding an id
// For this example, the id is fake. In your code, you should provide valid ids.
registry.addChatInputCommandIds('123456789123456789');
}
}
module.exports = {
UwUCommand
};

Adding from outside a command​

If you're outside of a command class, you'll have to manually acquire the registry first, and then add the ids or names to it. It'll look really similar to what we did in Registering Application Commands outside a Command.

const { ApplicationCommandRegistries } = require('@sapphire/framework');

const registry = ApplicationCommandRegistries.acquire('uwu');

// Adding a name
// NOT RECOMMENDED. Use the id methods with ids instead.
registry.addChatInputCommandNames('uwu');

// Adding an id
// For this example, this id is fake. In your code, you should provide valid ids.
registry.addChatInputCommandIds('123456789123456789');