Skip to main content

Using Subcommand groups

Before we start, we assume you already know what subcommand groups are, if not please refer to the Official Discord Docs for more information.

Message Subcommand Groups

import { Subcommand } from '@sapphire/plugin-subcommands';import type { Args } from '@sapphire/framework';import type { Message } from 'discord.js';// Extend `Subcommand` instead of `Command`export class UserCommand extends Subcommand {  public constructor(context: Subcommand.Context, options: Subcommand.Options) {    super(context, {      ...options,      subcommands: [        {          name: 'adminroles',          type: 'group',          entries: [            { name: 'add', messageRun: 'messageAdd' },            { name: 'remove', messageRun: 'messageRemove' },            { name: 'list', messageRun: 'messageList' }          ]        }      ]    });  }  public async messageAdd(message: Message, args: Args) {}  public async messageRemove(message: Message, args: Args) {}  public async messageList(message: Message, args: Args) {}}

Chat Input Subcommand Groups

import { Subcommand } from '@sapphire/plugin-subcommands';import type { Args } from '@sapphire/framework';// Extend `Subcommand` instead of `Command`export class UserCommand extends Subcommand {  public constructor(context: Subcommand.Context, options: Subcommand.Options) {    super(context, {      ...options,      subcommands: [        {          name: 'adminroles',          type: 'group',          entries: [            { name: 'add', chatInputRun: 'chatInputAdd' },            { name: 'remove', chatInputRun: 'chatInputRemove' },            { name: 'list', chatInputRun: 'chatInputList' }          ]        }      ]    });  }  public async chatInputAdd(interaction: Subcommand.ChatInputInteraction) {}  public async chatInputRemove(interaction: Subcommand.ChatInputInteraction) {}  public async chatInputList(interaction: Subcommand.ChatInputInteraction) {}}
note

To use subcommands on slash commands, you need to register the command first.