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

# Command

## `Decorator`

<table><thead><tr><th>parameter</th><th>type</th><th data-type="checkbox">required</th></tr></thead><tbody><tr><td>cooldown</td><td>number</td><td>true</td></tr><tr><td>guilds</td><td>string[]</td><td>true</td></tr><tr><td>builder</td><td>any</td><td>true</td></tr></tbody></table>

{% hint style="info" %}
You can specify guilds by their ids as an array. `["1", "2", "3"]` or `["*"]`
{% endhint %}

## `Template`

```typescript
import { Client, CommandInteraction, SlashCommandBuilder } from "discord.js";
import { Command } from "engine";

@Command(5, ["*"], new SlashCommandBuilder().setName("ping").setDescription("Replies with Pong!"))
export default class PingCommand {
	public static async callback(client: Client, interaction: CommandInteraction) {
		await interaction.reply("Pong!");
	}
}
```

## `Permissions`

```typescript
import { Client, CommandInteraction, SlashCommandBuilder, PermissionFlagsBits } from "discord.js";
import { Command } from "engine";

@Command(5, ["*"], new SlashCommandBuilder().setName("ping").setDescription("Replies with Pong!"))
export default class PingCommand {
	public static async callback(client: Client, interaction: CommandInteraction) {
		if (!interaction.memberPermissions?.has(PermissionFlagsBits.SendMessages)) {
			await interaction.reply({ content: "You do not have the required permissions to use this command.", ephemeral: true });
			return;
		}

		await interaction.reply("Pong!");
	}
}
```

{% hint style="info" %}
You can use `PermissionFlagsBits` [(all permissions)](https://discord.com/developers/docs/topics/permissions)
{% endhint %}

## `Globals` (only available to commands)

### Definition

```typescript
export const globals = {
	some_variable: "test",
};
```

### Usage

```typescript
client.globals.get("COMMAND_NAME")
```

### Example

```typescript
import { Client, CommandInteraction, SlashCommandBuilder, PermissionFlagsBits } from "discord.js";
import { Command } from "engine";

export const globals = {
	some_variable: "test",
};

@Command(5, ["*"], new SlashCommandBuilder().setName("ping").setDescription("Replies with Pong!"))
export default class PingCommand {
	public static async callback(client: Client, interaction: CommandInteraction) {
		const ping_globals = client.globals.get("ping")
		console.log(ping_globals.some_variable) // will log: test
		await interaction.reply("Pong!");
	}
}
```

## `Options`

```typescript
import { Client, CommandInteraction, SlashCommandBuilder, PermissionFlagsBits } from "discord.js";
import { Command, CommandOptions } from "engine";

export const globals = {
	some_variable: "test"
}

@Command(5, ["*"], new SlashCommandBuilder().setName("ping").setDescription("Replies with Pong!"))
export default class PingCommand {
	public static async callback(client: Client, interaction: CommandInteraction, options: CommandOptions) {
		
		const cooldown = options.cooldown; // is: 3
		const command_name = options.data.name; // is: ping

		// get current global variables
		const globals = client.globals.get(command_name);
		console.log(globals.some_variable); // is: test

		await interaction.reply("Pong!");
	}
}
```
