Skip to Content
nyx logonyx guide
Command Types

Context Menu Commands

Reading time:2 min read

Context menu commands are commands executed on special menus. Currently Discord has two types of context menus:

Creation

Creation

Extend the AbstractContextMenuCommand class:

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

Implementation

Implement data that stores the command's data, and the respective executeX() method:

  • executeMessage() for message context menus.
  • executeUser() for user context menus.
import { , , type  } from 'discord.js';
import {  } from '@nyx-discord/djs';

class  extends  {
  protected readonly  = new ()
    .('My Context Menu')
    .(.) // or ApplicationCommandType.Message
    .();

  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'];
  }
}

Execution Meta

The second argument of the execute methods 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.

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