Registering Application Commands outside a Command
You are able to register your application commands inside of their command class, but also outside of the class! Whether it's a dynamic command or premium command, Sapphire can help you manage your application commands with ease.
warning
You shouldn't use all three methods at the same time, just one is enough! This is just an example of all three variants.
- CommonJS
- ESM
- TypeScript
const { SlashCommandBuilder } = require('@discordjs/builders');
const { ApplicationCommandRegistries } = require('@sapphire/framework');
// Acquires the registry keyed by 'uwu'
const registry = ApplicationCommandRegistries.acquire('uwu');
// Registering with the discord.js options object
registry.registerChatInputCommand({
name: 'uwu',
description: 'Sends a uwu in chat'
});
// Registering with the builder
const builder = new SlashCommandBuilder().setName('uwu').setDescription('Sends a uwu in chat');
registry.registerChatInputCommand(builder);
// Registering with the builder provided by the method
registry.registerChatInputCommand((builder) => builder.setName('uwu').setDescription('Sends a uwu in chat'));
import { SlashCommandBuilder } from '@discordjs/builders';
import { ApplicationCommandRegistries } from '@sapphire/framework';
// Acquires the registry keyed by 'uwu'
const registry = ApplicationCommandRegistries.acquire('uwu');
// Registering with the discord.js options object
registry.registerChatInputCommand({
name: 'uwu',
description: 'Sends a uwu in chat'
});
// Registering with the builder
const builder = new SlashCommandBuilder().setName('uwu').setDescription('Sends a uwu in chat');
registry.registerChatInputCommand(builder);
// Registering with the builder provided by the method
registry.registerChatInputCommand((builder) => builder.setName('uwu').setDescription('Sends a uwu in chat'));
import { SlashCommandBuilder } from '@discordjs/builders';
import { ApplicationCommandRegistries } from '@sapphire/framework';
// Acquires the registry keyed by 'uwu'
const registry = ApplicationCommandRegistries.acquire('uwu');
// Registering with the discord.js options object
registry.registerChatInputCommand({
name: 'uwu',
description: 'Sends a uwu in chat'
});
// Registering with the builder
const builder = new SlashCommandBuilder().setName('uwu').setDescription('Sends a uwu in chat');
registry.registerChatInputCommand(builder);
// Registering with the builder provided by the method
registry.registerChatInputCommand((builder) => builder.setName('uwu').setDescription('Sends a uwu in chat'));