Skip to Content
nyx logonyx guide
Command TypesParent Commands

SubCommand Groups

Reading time:2 min read

It's recommended to read the Commands Overview, Parent Commands and SubCommands pages first.

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.

The 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');
const byName: SubCommand<InteractionTypes> | null
class extends { /** */ } const byClass = .();
const byClass: MySubCommandClass | null
const allChildren = .();
const allChildren: ReadonlyCollection<string, SubCommand<InteractionTypes>>

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.

On this page