Creating a Sub Commands
In order to create Sub Commands you need to create a parent
class command and then create the sub commands as classes that extends SubCommand
and finally you need to add the sub commands to the parent command using the @Options
decorator.
Note
Why we need to add the sub commands to the parent command using the @Options
decorator?
Well, the answer in simple words is because discord treats sub commands as options of the parent command. And following that way in seyfert you pass the sub commands as options to the parent command.
Let’s check an example. Suppose you have the following directory structure:
srcDirectory commands
Directory account
create.command.ts delete.command.ts parent.ts index.ts seyfert.config.js package.json tsconfig.json
import { Declare, Command, Options } from " seyfert " ;
import { CreateCommand } from " ./create.command " ;
import { DeleteCommand } from " ./delete.command " ;
description: " account command "
// Being in the same folder with @AutoLoad() you can save this
@Options ([CreateCommand, DeleteCommand])
export class AccountCommand extends Command {}
import { type CommandContext, Declare, SubCommand } from " seyfert " ;
description: " create a new something "
export class CreateCommand extends SubCommand {
run ( ctx : CommandContext ) {
content: " create command executed "
import { type CommandContext, Declare, SubCommand } from " seyfert " ;
description: " delete something "
export class DeleteCommand extends SubCommand {
run ( ctx : CommandContext ) {
content: " delete command executed "