LogoLogo
  • What is WildBeast?
  • Guides
    • Linux guides
      • Setup
      • Running as a service
  • Fundamentals
    • Commands
      • Slash commands
        • Subcommands
        • Options
        • Buttons
      • Context menu actions
    • Jobs
  • Extras
    • VPS recommendations
    • Creating a bot account
    • Adding your bot to your server
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Fundamentals
  2. Commands
  3. Slash commands

Subcommands

Nest multiple separate commands under one base command

PreviousSlash commandsNextOptions

Last updated 3 years ago

Was this helpful?

Subcommands are a great way to nest seperate commands under one base command, each subcommand is their own seperate command and can be called as such.

In practise

import { Interaction } from 'detritus-client'
import { BaseSlashCommand, BaseCommandOption } from '../base'

export default class PingCommand extends BaseSlashCommand {
  constructor () {
    super({
      name: 'ping',
      // With subcommands, the description doesn't matter,
      // since it doesn't get shown to end users.
      description: '',
      options: [
        new PongCommand()
      ]
    })
  }
  // The base command should not have a run(), it never gets called
}

export class PongCommand extends BaseCommandOption {
  constructor () {
    super({
      name: 'pong'
      description: 'Pong!'
    })
  }
  
  async run (context: Interaction.InteractionContext): Promise<void> {
    await context.editOrRespond(context, 'Pong!')
  }
}

We're continuing off the example from the page

Slash commands