Search…
Subcommands
Nest multiple separate commands under one base command
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

We're continuing off the example from the Slash commands page
1
import { Interaction } from 'detritus-client'
2
import { BaseSlashCommand, BaseCommandOption } from '../base'
3
4
export default class PingCommand extends BaseSlashCommand {
5
constructor () {
6
super({
7
name: 'ping',
8
// With subcommands, the description doesn't matter,
9
// since it doesn't get shown to end users.
10
description: '',
11
options: [
12
new PongCommand()
13
]
14
})
15
}
16
// The base command should not have a run(), it never gets called
17
}
18
19
export class PongCommand extends BaseCommandOption {
20
constructor () {
21
super({
22
name: 'pong'
23
description: 'Pong!'
24
})
25
}
26
27
async run (context: Interaction.InteractionContext): Promise<void> {
28
await context.editOrRespond(context, 'Pong!')
29
}
30
}
Copied!
Export as PDF
Copy link
Contents
In practise