Context Menu Commands
Context menu commands are commands executed on special menus. Currently Discord has two types of context menus:
- Message Context Menus, shown when right clicking on a message.
- User Context Menus, shown when right clicking on a user.
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!');
}
}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.Idfield. - The execution start date, via the
TypedFields.CreationDatefield. - The bot whose
Clientsent the interaction, via theTypedFields.Botfield.
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
Command components
Handle components interactions directly in the subcommand that sent them, without a separate interactionCreate listener.
Filters
Add pre-execution checks to your subcommand, like permissions or cooldowns.
Middlewares
Run code before every command's execution, like logging or pre-conditions.
