SubCommand Groups
Subcommand groups are non executable commands that have subcommand children. They are stored inside a Parent Command.
While they don't depend on a specific bot, they do depend on their parent (a parent command).
Creation
Creation
Extend the AbstractSubCommandGroup class:
import { } from '@nyx-discord/djs';
class extends {}Implementation
Implement data that stores the command's data. The group's children collection is provided by the base class.
data field must not contain any option, only the base values (name, description, etc). If they are included, they will be ignored.import { } from 'discord.js';
import { } from '@nyx-discord/djs';
class extends {
protected readonly = new ()
.('my-group')
.('My group')
.();
}Addition to its parent
Instantiate and add it to a parent command.
const = new ();
.();Or do it in the parent's class:
import { , } from '@nyx-discord/djs';
import { } from 'discord.js';
class extends {
constructor() {
super();
this.(new (this));
}
}Then it'll show up when the top-level parent command is registered.
Children management
Children aren't static: they can be added and removed in runtime.
.();
.();
.('sub-command-name');However, for the changes to be reflected in Discord, you must edit the parent command afterwards:
await .().();You can also query them by name, class or Collection:
import { } from '@nyx-discord/djs';
const byName = .('sub-command-name');
class extends { /** */ }
const byClass = .();
const allChildren = .();Metadata
When extending nyx with plugins, you may want to specify extra data for them. You can do so with the Metadata object, saved on the group.
While groups internally save a Metadata, the return type of #getMeta() is a ReadonlyMetadata,
meaning that external objects can read the object, but not modify it.
import { } from '@nyx-discord/djs';
class extends {
protected override readonly = {
: 'someValue',
};
}
const = new ();
const = .();
const = ['someKey']; // 'someValue'For a more type-safe approach, you can use TypedFields. Check the Metadata page for more information.
