> ## Documentation Index
> Fetch the complete documentation index at: https://stars-components.js.org/llms.txt
> Use this file to discover all available pages before exploring further.

# @wolfstar/plugin-subcommands-advanced

> Modularize slash subcommands into separate command classes.

<CodeGroup>
  ```bash npm theme={"system"}
  npm install @wolfstar/plugin-subcommands-advanced
  ```

  ```bash pnpm theme={"system"}
  pnpm add @wolfstar/plugin-subcommands-advanced
  ```

  ```bash yarn theme={"system"}
  yarn add @wolfstar/plugin-subcommands-advanced
  ```

  ```bash bun theme={"system"}
  bun add @wolfstar/plugin-subcommands-advanced
  ```
</CodeGroup>

<CardGroup cols={2}>
  <Card title="npm" icon="npm" horizontal href="https://npmx.dev/package/@wolfstar/plugin-subcommands-advanced" />

  <Card title="Source" icon="github" horizontal href="https://github.com/wolfstar-project/plugins/tree/main/packages/plugin-subcommands-advanced" />
</CardGroup>

<Tip>See the [Plugins guide](/guide/plugins) for how plugins from wolfstar-project/plugins fit alongside the core framework.</Tip>

<div align="center">
  <img src="https://cdn.wolfstar.rocks/wolfstar-assets/wolfstar.png" alt="WolfStar" width="100" />

  # @wolfstar/plugin-subcommands-advanced

  **Modular slash subcommands for `@wolfstar/http-framework`.**

  [![version](https://npmx.dev/api/registry/badge/version/@wolfstar/plugin-subcommands-advanced)](https://npmx.dev/package/@wolfstar/plugin-subcommands-advanced)
  [![downloads](https://npmx.dev/api/registry/badge/downloads/@wolfstar/plugin-subcommands-advanced)](https://npmx.dev/package/@wolfstar/plugin-subcommands-advanced)
  [![license](https://img.shields.io/github/license/wolfstar-project/plugins?style=flat-square\&color=informational)](https://github.com/wolfstar-project/plugins/blob/main/LICENSE)
</div>

## Description

Plugin for [`@wolfstar/http-framework`](https://www.npmjs.com/package/@wolfstar/http-framework) that lets you split slash **subcommands** (and subcommand groups) into **separate command classes**, instead of putting every handler method on the parent.

Adapted from [`@kaname-png/plugin-subcommands-advanced`](https://github.com/sawa-ko/neko-plugins/tree/main/packages/subcommands-advanced) for WolfStar’s HTTP interaction framework.

## Installation

```bash theme={"system"}
pnpm add @wolfstar/http-framework @wolfstar/plugin-subcommands-advanced
```

## Usage

Import the register entrypoint **before** creating the client:

```typescript theme={"system"}
import '@wolfstar/plugin-subcommands-advanced/register';
import { Client, RegisterCommand } from '@wolfstar/http-framework';
import { Command, Subcommand, RegisterAsSubcommand, RegisterAsSubcommandGroup } from '@wolfstar/plugin-subcommands-advanced';

const client = new Client({
	subcommandsAdvanced: {
		// optional: piece names become parent/sub or parent/group/sub
		nameCommandsAutogenerated: true
	}
});
```

Recommended layout:

```text theme={"system"}
commands/
└── utils/
    ├── parent.ts          // parent chat-input command
    ├── ping.ts            // subcommand
    └── poll/
        └── create.ts      // grouped subcommand
```

### Parent command

```typescript theme={"system"}
import { RegisterCommand } from '@wolfstar/http-framework';
import { Subcommand } from '@wolfstar/plugin-subcommands-advanced';

@RegisterCommand((builder) =>
	builder
		.setName('utils')
		.setDescription('Utility commands')
		.addSubcommandGroup((group) => group.setName('poll').setDescription('Poll tools'))
)
export class UtilsCommand extends Subcommand {}
```

### Direct subcommand

```typescript theme={"system"}
import { Command, RegisterAsSubcommand } from '@wolfstar/plugin-subcommands-advanced';

@RegisterAsSubcommand('utils', (builder) => builder.setName('ping').setDescription('Ping the bot'))
export class PingCommand extends Command {
	public override chatInputRun(interaction: Command.ChatInputInteraction) {
		return interaction.reply({ content: 'Pong!' });
	}
}
```

### Grouped subcommand

```typescript theme={"system"}
import { Command, RegisterAsSubcommandGroup } from '@wolfstar/plugin-subcommands-advanced';

@RegisterAsSubcommandGroup('utils', 'poll', (builder) => builder.setName('create').setDescription('Create a poll'))
export class PollCreateCommand extends Command {
	public override chatInputRun(interaction: Command.ChatInputInteraction) {
		return interaction.reply({ content: 'Created!' });
	}
}
```

### Constructor options (no decorators)

```typescript theme={"system"}
import { Command } from '@wolfstar/plugin-subcommands-advanced';

export class PingCommand extends Command {
	public constructor(context: Command.LoaderContext, options: Command.Options) {
		super(context, {
			...options,
			registerSubCommand: {
				parentCommandName: 'utils',
				slashSubcommand: (builder) => builder.setName('ping').setDescription('Ping!')
			}
		});
	}

	public override chatInputRun(interaction: Command.ChatInputInteraction) {
		return interaction.reply({ content: 'Pong!' });
	}
}
```

## How it works

`@wolfstar/http-framework` routes subcommands to **methods on the parent** command instance. This plugin:

1. Lets child command classes register themselves into in-memory registries (by parent name).
2. After all command pieces are constructed, rebuilds the parent’s chat-input resolver and `CommandRouter`, installing thin delegate methods that call each child’s `chatInputRun`.

You do not need to call the optional `hooks.subcommands` / `hooks.groups` helpers unless you are registering the parent imperatively and want to attach builders yourself.

## Notes

* HTTP-only: there is no message-command support (unlike the Sapphire original).
* Child classes should **not** use `@RegisterCommand` — only the parent registers the top-level slash command.
* Subcommand groups must still be declared on the parent (via `@RegisterCommand` builder or `registerApplicationCommands`).
