> 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-group.md).

# SlashCommandGroup

Group slash subcommands under one top-level command, and define user/message context menus.

**Package:** `@nexora.ts/core`

## Beginner — `group()` factory

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

class CreateSub extends SlashCommand {
  name = 'create';
  description = 'Open a ticket';
  async execute(ctx: CommandContext) {
    await ctx.success('Ticket created.');
  }
}

class CloseSub extends SlashCommand {
  name = 'close';
  description = 'Close your ticket';
  async execute(ctx: CommandContext) {
    await ctx.reply('Ticket closed.');
  }
}

// Pass class constructors — group() instantiates them
export default group('ticket', 'Ticket system', [CreateSub, CloseSub], {
  guildOnly: true,
});
```

Users run `/ticket create` and `/ticket close`.

## Class style

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

class CreateSub extends SlashCommand {
  name = 'create';
  description = 'Open a ticket';

  async execute(ctx: CommandContext) {
    await ctx.reply('Ticket created.');
  }
}

class CloseSub extends SlashCommand {
  name = 'close';
  description = 'Close your ticket';
  guildOnly = true;

  async execute(ctx: CommandContext) {
    await ctx.reply('Ticket closed.');
  }
}

export default class TicketGroup extends SlashCommandGroup {
  name = 'ticket';
  description = 'Ticket system';
  commands = [new CreateSub(), new CloseSub()];
}
```

### Fields

| Field         | Description                                                          |
| ------------- | -------------------------------------------------------------------- |
| `name`        | Top-level slash command name                                         |
| `description` | Top-level description                                                |
| `commands`    | Array of `SlashCommand` instances (subcommand name = `command.name`) |

Also: `subcommands(CreateCmd, CloseCmd)` to instantiate class constructors.

Discovery registers the group as one chat-input command with subcommand options. Runtime routing calls the matching child’s `execute`.

## ContextMenuCommand

Right-click / Apps menu commands for users or messages.

```ts
import { ContextMenuCommand, type ContextMenuContext } from '@nexora.ts/core';

export default class UserInfoMenu extends ContextMenuCommand {
  name = 'User info';
  type = 'user' as const;

  async execute(ctx: ContextMenuContext) {
    const user = ctx.targetUser;
    await ctx.success(`${user?.tag} · \`${user?.id}\``);
  }
}
```

```ts
export default class ReportMessage extends ContextMenuCommand {
  name = 'Report message';
  type = 'message' as const;

  async execute(ctx: ContextMenuContext) {
    const msg = ctx.targetMessage;
    await ctx.reply({
      content: `Reported message ${msg.id}`,
      ephemeral: true,
    });
  }
}
```

### Fields & context

| Field / helper                        | Description                          |
| ------------------------------------- | ------------------------------------ |
| `name`                                | Menu label (shown in Discord)        |
| `type`                                | `'user'` or `'message'`              |
| `execute(ctx)`                        | Handler                              |
| `ctx.targetUser`                      | Target user (`type: 'user'`)         |
| `ctx.targetMessage`                   | Target message (`type: 'message'`)   |
| `ctx.reply` / `success` / `defer` / … | Same style as slash `CommandContext` |

Deployed as Application Command type User / Message alongside slash commands.

## Related

* [SlashCommand](/nexora.ts/framework/slash-command.md)
* [Commands guide](/nexora.ts/commands-and-interactions/commands.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-group.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.
