[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/prismarine](https://jsprismarine.dev/api/@jsprismarine/prismarine/index.md) / command/CommandExecutor

# command/CommandExecutor

## Interfaces

### CommandExecutor

Defined in: [packages/prismarine/src/command/CommandExecutor.ts:12](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/CommandExecutor.ts#L12)

Something that can issue a command and be answered.

A player and the server console have exactly this much in common: a name and somewhere to
put a reply. They are not the same kind of thing otherwise - one stands at a position in a
world and the other is a terminal attached to the process - so this is an interface rather
than a shared base class. Making the console an entity to get these four methods is what
forced `isPlayer()` and `isConsole()` to exist in the first place.

#### Extended by

- [`PlayerCommandSender`](https://jsprismarine.dev/api/@jsprismarine/prismarine/command/CommandManager/index.md#playercommandsender)

#### Methods

##### getFormattedUsername()

> **getFormattedUsername**(): `string`

Defined in: [packages/prismarine/src/command/CommandExecutor.ts:32](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/CommandExecutor.ts#L32)

Get the formatted username of the executor.

###### Returns

`string`

The formatted username of the executor.

##### getName()

> **getName**(): `string`

Defined in: [packages/prismarine/src/command/CommandExecutor.ts:26](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/CommandExecutor.ts#L26)

Get the name of the executor.

###### Returns

`string`

The name of the executor.

##### getServer()

> **getServer**(): [`Server`](https://jsprismarine.dev/api/@jsprismarine/prismarine/Server/classes/Server.md)

Defined in: [packages/prismarine/src/command/CommandExecutor.ts:38](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/CommandExecutor.ts#L38)

Get the server instance.

###### Returns

[`Server`](https://jsprismarine.dev/api/@jsprismarine/prismarine/Server/classes/Server.md)

The server instance.

##### sendMessage()

> **sendMessage**(`message`): `void` \| `Promise`\<`void`\>

Defined in: [packages/prismarine/src/command/CommandExecutor.ts:20](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/CommandExecutor.ts#L20)

Send a message to the executor.

Delivery is asynchronous for a player, whose message goes out over the wire, and
synchronous for the console, which writes to a terminal. Callers may await either.

###### Parameters

###### message

`string`

The message to send.

###### Returns

`void` \| `Promise`\<`void`\>

## Type Aliases

### CommandTarget

> **CommandTarget** = [`CommandExecutor`](#commandexecutor) \| `Pick`\<[`CommandExecutor`](#commandexecutor), `"getName"`\>

Defined in: [packages/prismarine/src/command/CommandExecutor.ts:45](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/CommandExecutor.ts#L45)

Whatever a command can be run as: an executor, or an entity a selector named, which has a name
to report but nowhere to put a reply.

## Functions

### isCommandExecutor()

> **isCommandExecutor**(`target`): `target is CommandExecutor`

Defined in: [packages/prismarine/src/command/CommandExecutor.ts:51](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/command/CommandExecutor.ts#L51)

Whether a command target can be answered, which is what separates an executor from any other
entity. Checks for `sendMessage` with `in`, because that member is the whole difference.

#### Parameters

##### target

[`CommandTarget`](#commandtarget)

#### Returns

`target is CommandExecutor`
