Skip to Content
nyx logonyx guide
Command Types

Parent Commands

Reading time:1 min read

It's recommended to read the Commands Overview page first.

Parent commands are top-level, non executable commands that can have children, which can be either subcommands commands or subcommand groups.

Creation

Creation

Extend the AbstractParentCommand class:

import {  } from '@nyx-discord/djs';

class  extends  {}

Implementation

Implement data that stores the command's data.

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-command')
    .('My command')
    .();
}

Registration

Instantiate and register it to a bot's CommandManager.

await .().(new ());

Guild deployment

By default, all commands will be deployed in the global scope. If you want to deploy them in a specific guild, you can do so by implementing the getGuilds() method.

import {  } from '@nyx-discord/djs';

class  extends  {
  public () {
    return ['GUILD_ID', 'ANOTHER_GUILD_ID'];
  }
}

If you're ever overriding from another base command, you can return null to make it global again, this is the default implementation.

Children management

Children aren't static: they can be added and removed in runtime.

.(, );
.();
.('sub-command-group-name');

However, for the changes to be reflected in Discord, you must edit the 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> | SubCommandGroup<InteractionTypes> | null
class extends { /** */ } const byClass = .();
const byClass: MySubCommandClass | null
const allChildren = .();
const allChildren: ReadonlyCollection<string, SubCommand<InteractionTypes> | SubCommandGroup<InteractionTypes>>

On this page