Subcommands
Reading time:1 min read
A command with subcommands has no options of its own, so chatInput() takes a list of subcommands instead. Create each one with subcommand(), and group them with group():
import { , , , } from '@nyx-discord/typed-options';
const = ({
: 'add',
: 'Add a tag',
: {
: ({ : 'The tag name', : true }),
},
});
const = ({ : 'purge', : 'Delete every tag' });
const = ({
: 'tag',
: 'Manage tags',
: [, ({ : 'admin', : 'Admin tools', : [] })],
});Reading a subcommand's options
Subcommand and group names are typed as string, so which subcommand ran is not inferred from the interaction. Instead, pass the subcommand's own data to typedOptions() to type its options:
const = ({
: 'add',
: 'Add a tag',
: {
: ({ : 'The tag name', : true }),
},
});
const = (, );
const name = .('name');This fits nyx's subcommands, which already live in their own class: define the subcommand's data there and read the options from it.
With raw payloads, typedOptions() finds the options inside the subcommand (and its group) for you.
