> For the complete documentation index, see [llms.txt](https://cjays-organization.gitbook.io/nexora.ts/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cjays-organization.gitbook.io/nexora.ts/framework/slash-command.md).

# SlashCommand

Abstract base class for slash commands. Same discovery as `command({…})` / `slash(…)` — export `default` from a file under `commands/`.

**Package:** `@nexora.ts/core`\
**Alias:** `BaseCommand` (extends `SlashCommand`)

## Beginner (shortest path)

```ts
import { slash } from '@nexora.ts/core';

export default slash('ping', 'Check latency', async (ctx) => {
  await ctx.reply('Pong!');
});
```

Private admin reply in one line:

```ts
import { slash } from '@nexora.ts/core';

export default slash('ban', 'Ban a member', async (ctx) => {
  const user = ctx.options.user('user', true);
  await ctx.success(`${user.tag} was banned.`);
}, {
  guildOnly: true,
  adminOnly: true,
  ephemeral: true, // all ctx.reply / embed default to ephemeral
  options: [
    { name: 'user', description: 'Member', type: 'user', required: true },
  ],
});
```

### Typed option getters

Prefer `ctx.options.*` over `ctx.interaction.options.get*`:

```ts
import { slash } from '@nexora.ts/core';

export default slash('echo', 'Echo text', async (ctx) => {
  const text = ctx.options.string('text', true);
  const times = ctx.options.integer('times') ?? 1;
  await ctx.reply(text.repeat(times));
}, {
  options: [
    { name: 'text', description: 'Text', type: 'string', required: true },
    { name: 'times', description: 'Repeat count', type: 'integer' },
  ],
});
```

Available: `string`, `integer`, `number`, `boolean`, `user`, `channel`, `role`, `mentionable`, `attachment`. Pass `true` as second arg when the option is required (narrows away `null`).

## Class style

```ts
import { SlashCommand, type CommandContext } from '@nexora.ts/core';

export default class PingCommand extends SlashCommand {
  name = 'ping';
  description = 'Check bot latency';

  async execute(ctx: CommandContext) {
    await ctx.reply('Pong!');
  }
}
```

## Full example (options & embeds)

```ts
import { SlashCommand, EmbedBuilder, type CommandContext } from '@nexora.ts/core';

export default class BanCommand extends SlashCommand {
  name = 'ban';
  description = 'Ban a member';
  guildOnly = true;
  adminOnly = true;
  cooldown = 5_000; // ms per user

  options = [
    { name: 'user', description: 'Member to ban', type: 'user' as const, required: true },
    { name: 'reason', description: 'Reason', type: 'string' as const, required: false },
  ];

  async execute(ctx: CommandContext) {
    const user = ctx.options.user('user', true);
    const reason = ctx.options.string('reason') ?? 'No reason';

    await ctx.reply(
      EmbedBuilder.success('Banned', `${user.tag} — ${reason}`).field(
        'Moderator',
        ctx.user.tag,
        true,
      ),
    );
  }
}
```

## Context helpers

Inside `execute(ctx)`:

| Helper                                                  | Description                                              |
| ------------------------------------------------------- | -------------------------------------------------------- |
| `ctx.reply(…)`                                          | string, embed builder, or options (`v2`, `ephemeral`, …) |
| `ctx.success` / `error` / `warn` / `info`               | colored embeds, **ephemeral by default**                 |
| `ctx.defer()` / `ctx.editReply()` / `ctx.followUp()`    | deferred flows                                           |
| `ctx.embed(builder)`                                    | reply with one embed                                     |
| `ctx.componentsV2(…)`                                   | Components V2 + `IsComponentsV2` flag                    |
| `ctx.user` / `ctx.guild` / `ctx.member` / `ctx.channel` | shortcuts                                                |
| `ctx.options.string/user/…`                             | typed option getters                                     |
| `ctx.interaction`                                       | raw discord.js interaction                               |

## Fields you can set

`name`, `description`, `options`, `guildOnly`, `adminOnly`, `permissions`, `cooldown`, `ephemeral`, `defaultMemberPermissions`, `dmPermission`, `guards`, `autocomplete?`, `execute`

## vs `command()` / `slash()`

```ts
// Object form — still valid
export default command({
  name: 'ping',
  description: 'Check latency',
  async execute(ctx) {
    await ctx.reply('Pong!');
  },
});
```

Prefer `slash()` for the shortest beginner path, `SlashCommand` when you want inheritance or shared base classes.

## Related

* [Commands guide](/nexora.ts/commands-and-interactions/commands.md)
* [EmbedBuilder](/nexora.ts/message-ui/embed-builder.md)
* [Nexora](/nexora.ts/framework/nexora.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://cjays-organization.gitbook.io/nexora.ts/framework/slash-command.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
