Skip to Content
nyx logonyx guide
Command Types

Standalone Commands

Reading time:3 min read

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

Standalone commands are fully executable, top level commands that don't store any children. In Discord, they are triggered on Slash Commands.

Creation

Creation

Extend the AbstractStandaloneCommand class:

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

class  extends  {}

Implementation

Implement data that stores the command's data, and execute() that executes the command.

import { , type  } from 'discord.js';
import {  } from '@nyx-discord/djs';

class  extends  {
  protected readonly  = new ()
    .('my-command')
    .('My command')
    .();

  public async (: ) {
    await .('Hello!');
  }
}

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.

Execution Meta

The second argument of the execute method is a Metadata object, which is a Record that stores metadata about the command call.

Apart from the keys saved by the caller or the middleware, the dispatch meta contains:

  • The execution ID, via the TypedFields.Id field.
  • The execution start date, via the TypedFields.CreationDate field.
  • The bot whose Client sent the interaction, via the TypedFields.Bot field.

To learn more about TypedFields, check the Metadata page.

Autocompletion

If your command has autocompletable options, you can implement the autocomplete() method.

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

class  extends  {
  public async (: ) {
    await .([
      { : 'First option', : 'first' },
      { : 'Second option', : 'second' },
    ]);
  }
}

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 command.

While commands 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.

Advanced features

Click on each card to learn more about that feature.

On this page