> ## Documentation Index
> Fetch the complete documentation index at: https://yor.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Yor.ts | classes/CommandContext

[yor.ts](../README) / [Exports](../modules) / CommandContext

# Class: CommandContext

## Hierarchy

* `BaseContext`

  ↳ **`CommandContext`**

## Table of contents

### Constructors

* [constructor](CommandContext#constructor)

### Properties

* [API](CommandContext#api)
* [applicationId](CommandContext#applicationid)
* [channel](CommandContext#channel)
* [client](CommandContext#client)
* [interactionId](CommandContext#interactionid)
* [member](CommandContext#member)
* [raw](CommandContext#raw)
* [subcommand](CommandContext#subcommand)
* [subcommandGroup](CommandContext#subcommandgroup)
* [token](CommandContext#token)
* [user](CommandContext#user)

### Methods

* [decorate](CommandContext#decorate)
* [defer](CommandContext#defer)
* [deleteReply](CommandContext#deletereply)
* [editReply](CommandContext#editreply)
* [fetchReply](CommandContext#fetchreply)
* [followUp](CommandContext#followup)
* [getAttachmentOption](CommandContext#getattachmentoption)
* [getBooleanOption](CommandContext#getbooleanoption)
* [getChannelOption](CommandContext#getchanneloption)
* [getIntegerOption](CommandContext#getintegeroption)
* [getMemberOption](CommandContext#getmemberoption)
* [getNumberOption](CommandContext#getnumberoption)
* [getRoleOption](CommandContext#getroleoption)
* [getStringOption](CommandContext#getstringoption)
* [getUserOption](CommandContext#getuseroption)
* [inGuild](CommandContext#inguild)
* [reply](CommandContext#reply)
* [replyModal](CommandContext#replymodal)

## Constructors

### constructor

• **new CommandContext**(`client`, `data`): [`CommandContext`](CommandContext)

Constructs a new instance of the APIApplicationCommandInteractionData class.

#### Parameters

| Name     | Type                                        | Description                               |
| :------- | :------------------------------------------ | :---------------------------------------- |
| `client` | [`YorClient`](YorClient)                    | The client object.                        |
| `data`   | `APIChatInputApplicationCommandInteraction` | The data used to initialize the instance. |

#### Returns

[`CommandContext`](CommandContext)

#### Overrides

BaseContext.constructor

#### Defined in

[src/structures/Contexts/CommandContext.ts:50](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L50)

## Properties

### API

• `Private` **API**: [`YorClientAPI`](YorClientAPI)

#### Defined in

[src/structures/Contexts/CommandContext.ts:42](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L42)

***

### applicationId

• `Readonly` **applicationId**: `string`

#### Defined in

[src/structures/Contexts/CommandContext.ts:33](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L33)

***

### channel

• **channel**: [`Channel`](Channel)

#### Defined in

[src/structures/Contexts/CommandContext.ts:35](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L35)

***

### client

• **client**: [`YorClient`](YorClient)

#### Inherited from

BaseContext.client

#### Defined in

[src/structures/Base.ts:4](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Base.ts#L4)

***

### interactionId

• `Readonly` **interactionId**: `string`

#### Defined in

[src/structures/Contexts/CommandContext.ts:34](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L34)

***

### member

• **member**: `undefined` | [`Member`](Member)

#### Defined in

[src/structures/Contexts/CommandContext.ts:37](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L37)

***

### raw

• `Readonly` **raw**: `APIChatInputApplicationCommandInteraction`

#### Defined in

[src/structures/Contexts/CommandContext.ts:31](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L31)

***

### subcommand

• `Optional` **subcommand**: `APIApplicationCommandInteractionDataSubcommandOption`

#### Defined in

[src/structures/Contexts/CommandContext.ts:40](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L40)

***

### subcommandGroup

• `Optional` **subcommandGroup**: `APIApplicationCommandInteractionDataSubcommandGroupOption`

#### Defined in

[src/structures/Contexts/CommandContext.ts:39](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L39)

***

### token

• `Readonly` **token**: `string`

#### Defined in

[src/structures/Contexts/CommandContext.ts:32](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L32)

***

### user

• **user**: `undefined` | [`User`](User)

#### Defined in

[src/structures/Contexts/CommandContext.ts:36](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L36)

## Methods

### decorate

▸ **decorate**(`name`, `data`): `unknown`

Decorates the object with a new property.

#### Parameters

| Name   | Type      | Description                         |
| :----- | :-------- | :---------------------------------- |
| `name` | `string`  | The name of the property.           |
| `data` | `unknown` | The data to assign to the property. |

#### Returns

`unknown`

The decorated object.

#### Inherited from

BaseContext.decorate

#### Defined in

[src/structures/Contexts/BaseContext.ts:22](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/BaseContext.ts#L22)

***

### defer

▸ **defer**(`ephemeral?`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`void`>

Defers the execution of the function.

#### Parameters

| Name        | Type      | Default value | Description                              |
| :---------- | :-------- | :------------ | :--------------------------------------- |
| `ephemeral` | `boolean` | `false`       | Whether the message is ephemeral or not. |

#### Returns

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`void`>

A promise that resolves when the deferral is complete.

#### Defined in

[src/structures/Contexts/CommandContext.ts:86](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L86)

***

### deleteReply

▸ **deleteReply**(): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`void`>

Deletes a reply.

#### Returns

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`void`>

A promise that resolves when the reply is deleted.

#### Defined in

[src/structures/Contexts/CommandContext.ts:155](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L155)

***

### editReply

▸ **editReply**(`data`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`APIMessage`>

Edits a reply.

#### Parameters

| Name   | Type                                                                                                                                                                                                                            | Description                     |
| :----- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :------------------------------ |
| `data` | [`Omit`](https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys)\<`RESTPostAPIWebhookWithTokenJSONBody`, `"username"` \| `"avatar_url"`> & \{ `flags?`: `MessageFlags`  } & \{ `files?`: `RawFile`\[]  } | The data for editing the reply. |

#### Returns

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`APIMessage`>

A promise that resolves when the reply is edited.

#### Defined in

[src/structures/Contexts/CommandContext.ts:129](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L129)

***

### fetchReply

▸ **fetchReply**(): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`APIMessage`>

Fetches the reply asynchronously.

#### Returns

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`APIMessage`>

A promise that resolves when the original reply is fetched.

#### Defined in

[src/structures/Contexts/CommandContext.ts:164](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L164)

***

### followUp

▸ **followUp**(`data`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`APIMessage`>

Calls the followUp method of the API class with the provided data.

#### Parameters

| Name   | Type                                                                                                                                                                                                                            | Description                                   |
| :----- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :-------------------------------------------- |
| `data` | [`Omit`](https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys)\<`RESTPostAPIWebhookWithTokenJSONBody`, `"username"` \| `"avatar_url"`> & \{ `flags?`: `MessageFlags`  } & \{ `files?`: `RawFile`\[]  } | The data to be passed to the followUp method. |

#### Returns

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`APIMessage`>

A promise that resolves to an APIMessage object.

#### Defined in

[src/structures/Contexts/CommandContext.ts:201](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L201)

***

### getAttachmentOption

▸ **getAttachmentOption**\<`T`>(`name`, `index?`, `required?`): `T` extends `true` ? `APIAttachment` : `null` | `APIAttachment`

Retrieves the value of the attachment option from the interaction data.

#### Type parameters

| Name | Type              |
| :--- | :---------------- |
| `T`  | extends `boolean` |

#### Parameters

| Name        | Type              | Default value | Description                                |
| :---------- | :---------------- | :------------ | :----------------------------------------- |
| `name`      | `string`          | `undefined`   | The name of the attachment option.         |
| `index`     | `0` \| `2` \| `1` | `0`           | The index of the attachment option.        |
| `required?` | `T`               | `undefined`   | Whether the attachment option is required. |

#### Returns

`T` extends `true` ? `APIAttachment` : `null` | `APIAttachment`

The value of the attachment option, or null if it doesn't exist.

**`Throws`**

If the attachment option is required but doesn't exist.

#### Defined in

[src/structures/Contexts/CommandContext.ts:732](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L732)

***

### getBooleanOption

▸ **getBooleanOption**\<`T`>(`name`, `index?`, `required?`): `T` extends `true` ? `boolean` : `null` | `boolean`

Retrieves a boolean option from the command's options.

#### Type parameters

| Name | Type              |
| :--- | :---------------- |
| `T`  | extends `boolean` |

#### Parameters

| Name        | Type              | Default value | Description                                                        |
| :---------- | :---------------- | :------------ | :----------------------------------------------------------------- |
| `name`      | `string`          | `undefined`   | The name of the option to retrieve.                                |
| `index`     | `0` \| `2` \| `1` | `0`           | (Optional) The index of the option to retrieve. Defaults to 0.     |
| `required?` | `T`               | `undefined`   | (Optional) Specifies if the option is required. Defaults to false. |

#### Returns

`T` extends `true` ? `boolean` : `null` | `boolean`

* The value of the option, or null if the option is not found and not required.

#### Defined in

[src/structures/Contexts/CommandContext.ts:403](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L403)

***

### getChannelOption

▸ **getChannelOption**\<`T`>(`name`, `index?`, `required?`): `T` extends `true` ? [`Channel`](Channel) : `null` | [`Channel`](Channel)

Retrieves a channel option from the command's options.

#### Type parameters

| Name | Type              |
| :--- | :---------------- |
| `T`  | extends `boolean` |

#### Parameters

| Name        | Type              | Default value | Description                                                        |
| :---------- | :---------------- | :------------ | :----------------------------------------------------------------- |
| `name`      | `string`          | `undefined`   | The name of the option to retrieve.                                |
| `index`     | `0` \| `2` \| `1` | `0`           | (Optional) The index of the option to retrieve. Defaults to 0.     |
| `required?` | `T`               | `undefined`   | (Optional) Specifies if the option is required. Defaults to false. |

#### Returns

`T` extends `true` ? [`Channel`](Channel) : `null` | [`Channel`](Channel)

* The value of the option, or null if the option is not found and not required.

#### Defined in

[src/structures/Contexts/CommandContext.ts:595](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L595)

***

### getIntegerOption

▸ **getIntegerOption**\<`T`>(`name`, `index?`, `required?`): `T` extends `true` ? `number` : `null` | `number`

Retrieves an integer option from the API.

#### Type parameters

| Name | Type              |
| :--- | :---------------- |
| `T`  | extends `boolean` |

#### Parameters

| Name        | Type              | Default value | Description                            |
| :---------- | :---------------- | :------------ | :------------------------------------- |
| `name`      | `string`          | `undefined`   | The name of the option.                |
| `index`     | `0` \| `2` \| `1` | `0`           | The index of the option.               |
| `required?` | `T`               | `undefined`   | Whether the option is required or not. |

#### Returns

`T` extends `true` ? `number` : `null` | `number`

* The value of the option.

#### Defined in

[src/structures/Contexts/CommandContext.ts:345](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L345)

***

### getMemberOption

▸ **getMemberOption**\<`T`>(`name`, `index?`, `required?`): `T` extends `true` ? [`Member`](Member) : `null` | [`Member`](Member)

Retrieves a user option from the command's options.

#### Type parameters

| Name | Type              |
| :--- | :---------------- |
| `T`  | extends `boolean` |

#### Parameters

| Name        | Type              | Default value | Description                                                        |
| :---------- | :---------------- | :------------ | :----------------------------------------------------------------- |
| `name`      | `string`          | `undefined`   | The name of the option to retrieve.                                |
| `index`     | `0` \| `2` \| `1` | `0`           | (Optional) The index of the option to retrieve. Defaults to 0.     |
| `required?` | `T`               | `undefined`   | (Optional) Specifies if the option is required. Defaults to false. |

#### Returns

`T` extends `true` ? [`Member`](Member) : `null` | [`Member`](Member)

* The value of the option, or null if the option is not found and not required.

#### Defined in

[src/structures/Contexts/CommandContext.ts:662](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L662)

***

### getNumberOption

▸ **getNumberOption**\<`T`>(`name`, `index?`, `required?`): `T` extends `true` ? `number` : `null` | `number`

Retrieves a number option from the command's options.

#### Type parameters

| Name | Type              |
| :--- | :---------------- |
| `T`  | extends `boolean` |

#### Parameters

| Name        | Type              | Default value | Description                                                        |
| :---------- | :---------------- | :------------ | :----------------------------------------------------------------- |
| `name`      | `string`          | `undefined`   | The name of the option to retrieve.                                |
| `index`     | `0` \| `2` \| `1` | `0`           | (Optional) The index of the option to retrieve. Defaults to 0.     |
| `required?` | `T`               | `undefined`   | (Optional) Specifies if the option is required. Defaults to false. |

#### Returns

`T` extends `true` ? `number` : `null` | `number`

* The value of the option, or null if the option is not found and not required.

#### Defined in

[src/structures/Contexts/CommandContext.ts:287](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L287)

***

### getRoleOption

▸ **getRoleOption**\<`T`>(`name`, `index?`, `required?`): `T` extends `true` ? [`Role`](Role) : `null` | [`Role`](Role)

Retrieves a role option from the command's options.

#### Type parameters

| Name | Type              |
| :--- | :---------------- |
| `T`  | extends `boolean` |

#### Parameters

| Name        | Type              | Default value | Description                                                        |
| :---------- | :---------------- | :------------ | :----------------------------------------------------------------- |
| `name`      | `string`          | `undefined`   | The name of the option to retrieve.                                |
| `index`     | `0` \| `2` \| `1` | `0`           | (Optional) The index of the option to retrieve. Defaults to 0.     |
| `required?` | `T`               | `undefined`   | (Optional) Specifies if the option is required. Defaults to false. |

#### Returns

`T` extends `true` ? [`Role`](Role) : `null` | [`Role`](Role)

* The value of the option, or null if the option is not found and not required.

#### Defined in

[src/structures/Contexts/CommandContext.ts:528](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L528)

***

### getStringOption

▸ **getStringOption**\<`T`>(`name`, `index?`, `required?`): `T` extends `true` ? `string` : `null` | `string`

Retrieves a string option from the command's options.

#### Type parameters

| Name | Type              |
| :--- | :---------------- |
| `T`  | extends `boolean` |

#### Parameters

| Name        | Type              | Default value | Description                                                        |
| :---------- | :---------------- | :------------ | :----------------------------------------------------------------- |
| `name`      | `string`          | `undefined`   | The name of the option to retrieve.                                |
| `index`     | `0` \| `2` \| `1` | `0`           | (Optional) The index of the option to retrieve. Defaults to 0.     |
| `required?` | `T`               | `undefined`   | (Optional) Specifies if the option is required. Defaults to false. |

#### Returns

`T` extends `true` ? `string` : `null` | `string`

* The value of the option, or null if the option is not found and not required.

#### Defined in

[src/structures/Contexts/CommandContext.ts:227](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L227)

***

### getUserOption

▸ **getUserOption**\<`T`>(`name`, `index?`, `required?`): `T` extends `true` ? [`User`](User) : `null` | [`User`](User)

Retrieves a user option from the command's options.

#### Type parameters

| Name | Type              |
| :--- | :---------------- |
| `T`  | extends `boolean` |

#### Parameters

| Name        | Type              | Default value | Description                                                        |
| :---------- | :---------------- | :------------ | :----------------------------------------------------------------- |
| `name`      | `string`          | `undefined`   | The name of the option to retrieve.                                |
| `index`     | `0` \| `2` \| `1` | `0`           | (Optional) The index of the option to retrieve. Defaults to 0.     |
| `required?` | `T`               | `undefined`   | (Optional) Specifies if the option is required. Defaults to false. |

#### Returns

`T` extends `true` ? [`User`](User) : `null` | [`User`](User)

* The value of the option, or null if the option is not found and not required.

#### Defined in

[src/structures/Contexts/CommandContext.ts:461](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L461)

***

### inGuild

▸ **inGuild**(): `boolean`

Checks if the instance is in a guild.

#### Returns

`boolean`

Returns true if the instance is in a guild, otherwise false.

#### Defined in

[src/structures/Contexts/CommandContext.ts:215](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L215)

***

### reply

▸ **reply**(`data`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`void`>

Replies to an interaction.

#### Parameters

| Name   | Type                                                                                                                                                                                                                            | Description                      |
| :----- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | :------------------------------- |
| `data` | [`Omit`](https://www.typescriptlang.org/docs/handbook/utility-types.html#omittype-keys)\<`RESTPostAPIWebhookWithTokenJSONBody`, `"username"` \| `"avatar_url"`> & \{ `flags?`: `MessageFlags`  } & \{ `files?`: `RawFile`\[]  } | The data for creating the reply. |

#### Returns

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`void`>

A promise that resolves when the reply is sent.

#### Defined in

[src/structures/Contexts/CommandContext.ts:106](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L106)

***

### replyModal

▸ **replyModal**(`data`): [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`void`>

Reply to a modal.

#### Parameters

| Name   | Type                                      | Description                      |
| :----- | :---------------------------------------- | :------------------------------- |
| `data` | `APIModalInteractionResponseCallbackData` | The data for creating the modal. |

#### Returns

[`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`void`>

A promise that resolves when the modal is created.

#### Defined in

[src/structures/Contexts/CommandContext.ts:177](https://github.com/OreOreki/yor.ts/blob/ff21935/src/structures/Contexts/CommandContext.ts#L177)
