Sunar

Group

The Group class handles slash commands with subcommands, allowing for structured and efficient management of hierarchical commands under a single root.

Usage

import { Group, execute } from 'sunar';
 
const group = new Group('root', 'parent', 'sub');
 
execute(group, (interaction) => {
	// handle execution
});
 
export { group };

Implementation

The following example demonstrates how to implement a Group using Sunar:

Create the root command

src/commands/example/root.js
import { Slash } from 'sunar';
import { ApplicationCommandOptionType } from 'discord.js';
 
const slash = new Slash({
	name: 'example',
	description: 'this is a example',
	options: [
		{
			name: 'parent',
			description: 'this is the parent',
			type: ApplicationCommandOptionType.SubcommandGroup,
			options: [
				{
					name: 'sub',
					description: 'this is the sub',
					type: ApplicationCommandOptionType.Subcommand
				},
			],
		},
	],
});
 
export { slash };

Create the sub command

src/commands/example/parent/sub.js
import { Group, execute } from 'sunar';
 
const group = new Group('example', 'parent', 'sub');
 
// protect(group, [...])
// config(group, {...})
 
execute(group, (interaction) => {
	// handle execution
});
 
export { group };

The name and paths of the files do not affect how it works!

Reference

GroupConfig

PropTypeDefault
cooldown
CooldownResolvable
-

Last updated on

On this page

GitHubEdit on Github ↗