# 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!");
	}
}
```


---

# Agent Instructions: 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:

```
GET https://discord-base.gitbook.io/discord-base/templates/command.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
