Acquiring an Application Command Registry
To work with an application command registry, you must "acquire" one for your commands. We can do this by using the
pre-defined registry for a command through the registerApplicationCommands
method
argument of the Command
class.
- CommonJS
- ESM
- TypeScript
const { Command } = require('@sapphire/framework');
class PingCommand extends Command {
registerApplicationCommands(registry) {
// registry is unique to this command
}
}
module.exports = {
PingCommand
};
import { Command } from '@sapphire/framework';
export class PingCommand extends Command {
registerApplicationCommands(registry) {
// registry is unique to this command
}
}
import { ApplicationCommandRegistry, Command } from '@sapphire/framework';
export class PingCommand extends Command {
public override registerApplicationCommands(registry: ApplicationCommandRegistry) {
// registry is unique to this command
}
}
Acquiring and accessing the application command registry this way is only associated with PingCommand
- it will not
interact with any other of your commands.
For most users, the method above should suffice. Another way of acquiring an application command registry is through
ApplicationCommandRegistries.acquire()
, but it should only be chosen for advanced usage such as handling application
command registration outside a command or creating TypeScript decorators.
- CommonJS
- ESM
- TypeScript
const { ApplicationCommandRegistries } = require('@sapphire/framework');
// Acquires the registry keyed by 'ping'
const pingRegistry = ApplicationCommandRegistries.acquire('ping');
import { ApplicationCommandRegistries } from '@sapphire/framework';
// Acquires the registry keyed by 'ping'
const pingRegistry = ApplicationCommandRegistries.acquire('ping');
import { ApplicationCommandRegistries } from '@sapphire/framework';
// Acquires the registry keyed by 'ping'
const pingRegistry = ApplicationCommandRegistries.acquire('ping');
Read Registering Application Commands outside a Command for more details