# Commands Overview (https://nyx-discord.github.io/nyx/guide/use/commands)

Commands are how your bot responds to user interactions.

<Callout type="warn" title="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.
</Callout>

## Quick example [#quick-example]

Let's create a simple ping command:

<Tabs items={['discord.js', '@discordjs/core', 'HTTP']}>
  <Tab>
```ts twoslash
import { type NyxBot } from '@nyx-discord/djs';
declare const bot: NyxBot;
// ---cut---
import { SlashCommandBuilder, type ChatInputCommandInteraction } from 'discord.js';
import { AbstractStandaloneCommand } from '@nyx-discord/djs';

class PingCommand extends AbstractStandaloneCommand {
  protected readonly data = new SlashCommandBuilder()
    .setName('ping')
    .setDescription('Replies with Pong!')
    .toJSON();

  public async execute(interaction: ChatInputCommandInteraction) {
    await interaction.reply('Pong!');
  }
}

// Register the command
await bot.getCommandManager().addCommands(new PingCommand());
```
  </Tab>
  <Tab>
```ts twoslash
import { type NyxBot } from '@nyx-discord/djs-core';
declare const bot: NyxBot;
// ---cut---
import type { APIChatInputApplicationCommandInteraction, ToEventProps } from '@discordjs/core';
import { AbstractStandaloneCommand } from '@nyx-discord/djs-core';

class PingCommand extends AbstractStandaloneCommand {
  protected readonly data = {
    name: 'ping',
    description: 'Replies with Pong!',
  };

  public async execute(interaction: ToEventProps<APIChatInputApplicationCommandInteraction>) {
    await interaction.api.interactions.reply(
      interaction.data.id,
      interaction.data.token,
      { content: 'Pong!' },
    );
  }
}

// Register the command
await bot.getCommandManager().addCommands(new PingCommand());
```
  </Tab>
  <Tab>
  Same as `@discordjs/core`, importing from `@nyx-discord/http`:

```ts twoslash
import { type NyxBot } from '@nyx-discord/http';
declare const bot: NyxBot;
// ---cut---
import type { APIChatInputApplicationCommandInteraction, ToEventProps } from '@discordjs/core';
import { AbstractStandaloneCommand } from '@nyx-discord/http';

class PingCommand extends AbstractStandaloneCommand {
  protected readonly data = {
    name: 'ping',
    description: 'Replies with Pong!',
  };

  public async execute(interaction: ToEventProps<APIChatInputApplicationCommandInteraction>) {
    await interaction.api.interactions.reply(
      interaction.data.id,
      interaction.data.token,
      { content: 'Pong!' },
    );
  }
}

// Register the command
await bot.getCommandManager().addCommands(new PingCommand());
```
  </Tab>
</Tabs>

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 [#command-deployment]

For commands to be deployed at Discord, you must either pass `deployCommands: true` when creating the bot, or deploy them manually.

<Tabs items={['discord.js', '@discordjs/core', 'HTTP']}>
  <Tab>
```ts twoslash
import { Client } from 'discord.js';
declare const client: Client<boolean>;
// ---cut---
import { Bot } from '@nyx-discord/djs';

const myBot = Bot.create((bot) => ({
  // ---cut-start---
  token: 'TOKEN', client: client, logger: console,
  // ---cut-end---
  // ... other options
  deployCommands: true,
}));
```
  </Tab>
  <Tab>
```ts twoslash
import { Client, GatewayIntentBits } from '@discordjs/core';
import { REST } from '@discordjs/rest';
import { WebSocketManager } from '@discordjs/ws';
const rest = new REST({ version: '10' }).setToken('TOKEN');
const gateway = new WebSocketManager({ token: 'TOKEN', intents: GatewayIntentBits.Guilds, rest });
const client = new Client({ rest, gateway });
// ---cut---
import { Bot, CoreNyxClient } from '@nyx-discord/djs-core';

const myBot = Bot.create((bot) => ({
  // ---cut-start---
  token: 'TOKEN', client: new CoreNyxClient(client, gateway, 'APPLICATION_ID'), logger: console,
  // ---cut-end---
  // ... other options
  deployCommands: true,
}));
```
  </Tab>
  <Tab>
```ts twoslash
import { HttpBot } from '@nyx-discord/http';

const myBot = HttpBot.create((bot) => ({
  // ---cut-start---
  applicationId: 'APPLICATION_ID', publicKey: 'PUBLIC_KEY', token: 'TOKEN', logger: console,
  // ---cut-end---
  // ... other options
  deployCommands: true,
}));
```
  </Tab>
</Tabs>

Then, when starting the bot, it will automatically deploy them.

You can also deploy manually:

<Callout type="error">This will throw if you passed `deployCommands: true` or already called it before.</Callout>

<Tabs items={['discord.js', '@discordjs/core', 'HTTP']}>
  <Tab>
```ts twoslash
import { Bot } from '@nyx-discord/djs';
declare const bot: Bot;
// ---cut---
await bot.getCommandManager().deploy();
```
  </Tab>
  <Tab>
```ts twoslash
import { Bot } from '@nyx-discord/djs-core';
declare const bot: Bot;
// ---cut---
await bot.getCommandManager().deploy();
```
  </Tab>
  <Tab>
  Same as `@discordjs/core`, importing from `@nyx-discord/http`:

```ts twoslash
import { Bot } from '@nyx-discord/http';
declare const bot: Bot;
// ---cut---
await bot.getCommandManager().deploy();
```
  </Tab>
</Tabs>

### Add or deploy first? [#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 [#command-types]

Commands are categorized into several types, depending on their purposes:

<Callout>Click on each card to learn more about that type.</Callout>

<Cards>
  <Card href="commands/types/standalone" title="Standalone Commands" icon={<CommandIcon />} external={false}>
    Slash commands with no children, like `/ping` or `/help`.
  </Card>
  <Card href="commands/types/parent" title="Parent Commands" icon={<FolderIcon />} external={false}>
    Slash commands that contain subcommands or subcommand groups, like `/user` with `/user info`.
  </Card>
  <Card href="commands/types/parent/subcommand" title="SubCommands" icon={<BabyIcon />} external={false}>
    Executable commands that live inside parents or subcommand groups, like `info` in a `/user` parent.
  </Card>
  <Card href="commands/types/parent/subcommand-group" title="SubCommand Groups" icon={<FoldersIcon />} external={false}>
    Non executable groups inside parent commands, like `settings` in a `/user settings view` command.
  </Card>
  <Card href="commands/types/context-menu" title="Context Menu Commands" icon={<PictureInPicture />} external={false}>
    Commands that appear when users right-click on messages or users.
  </Card>
</Cards>
