> For the complete documentation index, see [llms.txt](https://docs.quickclient.cc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.quickclient.cc/en/extras/commands.md).

# Your own commands

How to add your own chat command to a script, with subcommands and completion.

A script can add its own chat command, for example `.home`. `command(name)` builds a Quick command with the `.` prefix, and it works while the script is enabled. When the script is disabled, the command stops responding and disappears from completion. Always call `register()` at the end, otherwise the command will not appear.

```java
@Override
public void activate() {
    command("home")
            .usage("<go|list>")
            .alias("h")
            .sub("go", go -> go
                    .completes(0, "base", "farm")
                    .runs(context -> context.reply("going to " + context.arg(0))))
            .sub("list", list -> list.runs(context -> context.reply("base, farm")))
            .register();
}
```

## How it works

* `home` is the command name and `h` is its second name, so `.h go base` works too.
* `go` and `list` have their own handlers. The `base` and `farm` suggestions appear on the first argument of `go`.
* `context.reply` sends the answer to the player's chat.

Arguments are everything after the command path, split by spaces. For `.home go base` the path is `home go` and there is one argument: `base`. Argument indexes in completion start at zero.

## Command

| Method                         | Type      | Description                                                                |
| ------------------------------ | --------- | -------------------------------------------------------------------------- |
| `usage(text)`                  | `Command` | a hint Quick adds to the error message when an argument is missing         |
| `alias(alias)`                 | `Command` | another name for the same command with all its subcommands                 |
| `runs(handler)`                | `Command` | the command handler; receives `CommandContext` and runs on the game thread |
| `sub(name, body)`              | `Command` | a subcommand; in `body` you describe it with the same builder              |
| `completes(index, options...)` | `Command` | fixed completion options for an argument                                   |
| `completes(index, supplier)`   | `Command` | options from a supplier, called while the player is typing                 |
| `register()`                   | `void`    | registers the command together with its aliases                            |

There are also helper getters `name()`, `aliases()`, `usage()`, `subs()`, `complete(index)`. They only read what was set in the builder.

## CommandContext

| Method                              | Type            | Description                                                |
| ----------------------------------- | --------------- | ---------------------------------------------------------- |
| `label()`                           | `String`        | the full command path, for example `home go`               |
| `args()`                            | `List<String>`  | arguments after the path                                   |
| `argCount()`                        | `int`           | number of arguments                                        |
| `arg(index)`                        | `String`        | argument by index                                          |
| `argOr(index, fallback)`            | `String`        | the argument, or the fallback value if it is missing       |
| `intArg(index)`, `doubleArg(index)` | `int`, `double` | the argument as a number                                   |
| `booleanArg(index)`                 | `boolean`       | `true/on/yes/1` and `false/off/no/0`, case does not matter |
| `rest()`, `rest(fromIndex)`         | `String`        | arguments joined into one string                           |
| `reply(message)`                    | `void`          | an answer in chat marked with the command that sent it     |

If an argument is missing and you call `arg(index)`, Quick prints an error with `usage` to chat and the handler stops.

## Quick's own commands

Quick has built-in commands: `.script list`, `.script reload`, `.script toggle <name>`, `.script settings <name>`, `.script set <name> <id> <value>`, `.script dir`, `.script check`. Give your commands different names, because Quick's commands are registered first.


---

# 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://docs.quickclient.cc/en/extras/commands.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.
