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

# Commands

Commands allow you to execute specific actions in response to user input. Here's an example of how to create them step by step:

```javascript
function build(build) {
    build.registerCommand(CommandInfo.builder()
        .name("command")
        .aliases(["c", "cmd"])
        .description("Simple example command in MCJS")
        .permission("commands.command")
        .target(CommandTarget.ALL)
        .async(false)
        .build(), function (context) {
            API.message(context.getSender(), "&aHello World!");
            return true;
        });
}
```

Explanation of the code:

**Registering and Creating a Command:**

```javascript
build.registerCommand(CommandInfo.builder()...
```

You use the `registerCommand` method to register a new command. `CommandInfo.builder()` creates a command information object.

**Command Configuration:**

```javascript
.name("command")
.aliases(["c", "cmd"])
.description("Simple example command in MCJS")
.permission("commands.command")
.target(CommandTarget.ALL)
.async(false)
```

* `.name("command")`: Sets the command name as "command".
* `.aliases(["c", "cmd"])`: Assigns aliases to the command, in this case, "c" and "cmd".
* `.description("Simple example command in MCJS")`: Provides a description for the command.
* `.permission("commands.command")`: Defines the permission required to execute the command.
* `.target(CommandTarget.ALL)`: Specifies the command target (**ALL**, **PLAYER**, or **CONSOLE**).
* `.async(false)`: Indicates whether the command runs asynchronously or not. In this case, it is set to false, meaning it is synchronous.

**Command Function:**

```javascript
function (context) {
    API.message(context.getSender(), "&aHello World!");
    return true;
}
```

This is the function that will be executed when the command is invoked. In this example, it uses the `API.message` function to send a message to the command sender with the content "Hello World!". The function returns `true` to indicate that the command was executed successfully.
