Commands Overview
Commands are how your bot responds to user interactions.
About prefix/message content commands
Nyx only supports application commands. It doesn't and won't support message content commands (like !ping).
If you really need such functionality, you can implement it yourself using the messageCreate event, but this isn't advised. Application commands improve DX and UX significantly, and don't require a privileged intent to work.
Quick example
Let's create a simple ping command:
import { , type } from 'discord.js';
import { } from '@nyx-discord/djs';
class extends {
protected readonly = new ()
.('ping')
.('Replies with Pong!')
.();
public async (: ) {
await .('Pong!');
}
}
// Register the command
await .().(new ());That's it! Your bot now has a /ping command that replies with "Pong!" when used.
The framework doesn't store any state in the instance, so you can reuse it across multiple bot instances without any problems.
Command deployment
For commands to be deployed at Discord, you must either pass deployCommands: true when creating the bot, or deploy them manually.
import { } from '@nyx-discord/djs';
const = .(() => ({
// ... other options
: true,
}));Then, when starting the bot, it will automatically deploy them.
You can also deploy manually:
deployCommands: true or already called it before.await .().();Add or deploy first?
If you add a command after commands have already been deployed, the framework will have to make an API call to register it.
This is not recommended due to ratelimits, so it's best to add all the commands before deploying (you can add commands before starting the bot).
Command types
Commands are categorized into several types, depending on their purposes:
Standalone Commands
Slash commands with no children, like /ping or /help.
Parent Commands
Slash commands that contain subcommands or subcommand groups, like /user with /user info.
SubCommands
Executable commands that live inside parents or subcommand groups, like info in a /user parent.
SubCommand Groups
Non executable groups inside parent commands, like settings in a /user settings view command.
Context Menu Commands
Commands that appear when users right-click on messages or users.
