Sunar

Dynamic Registration

Dynamic registration allows you to programmatically register commands either globally or per server, providing flexibility in managing your bot's commands based on runtime conditions or configurations.

src/signals/ready.js
import { Signal, execute } from 'sunar';
import { registerCommands } from 'sunar/registry';
 
const signal = new Signal('ready', { once: true });
 
execute(signal, async (client) => {
	await registerCommands(client.application);
 
	console.log(`${client.user.tag} logged!`);
});
 
export { signal };

Specific Guilds IDs commands

To specify the servers on which a command should be registered you must pass it to them using the config mutator.

src/commands/ping.js
import { Slash, execute, config } from 'sunar';
 
const slash = new Slash({
	name: 'ping',
	description: "Ping the bot to check if it's online.",
});
 
config(slash, { 
	guildsIds: ['YOUR_GUILD_ID'],
}); 
 
execute(slash, (interaction) => {
	interaction.reply('Pong!');
});
 
export { slash };
Replace 'YOUR_GUILD_ID' with your actual guild IDs.

Last updated on

On this page

GitHubEdit on Github ↗