# executeCommandHandler (Server)

> Runs the handlers server scripts registered for a command, as if the player had typed it.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Server
- **Category**: Keyboard
- **URL**: https://wiki.mymp.gg/en/executeCommandHandler-server
- **Counterpart**: Also exists on the client, with its own implementation: [executeCommandHandler (Client)](https://wiki.mymp.gg/en/executeCommandHandler-client.md)

## Syntax

```lua
bool executeCommandHandler(string commandName, any ... [, element thePlayer = console])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `commandName` | `string` | The command's name. |
| `thePlayer` | `element` | The element passed to the handlers as whoever typed it: a player or the console. Pass `nil` to skip it. *(default: `console`)* |
| `...` | `any` | Arguments passed to the handlers, each turned into a string. |

## Returns

`true` if a running resource handled the command, `false` if none did.

It runs every resource's handlers, not only this one's. `onPlayerCommand` does not fire.

## Example

```lua
addEventHandler("onPlayerJoin", root, function()
    executeCommandHandler("spawn", source)
end)
```

## See also

- [addCommandHandler (Shared)](https://wiki.mymp.gg/en/addCommandHandler.md): Registers a function that runs when the command is typed in the console. The arguments arrive as space-separated strings.
- [removeCommandHandler (Shared)](https://wiki.mymp.gg/en/removeCommandHandler.md): Removes the handler this resource registered for a command.
- [executeCommandHandler (Client)](https://wiki.mymp.gg/en/executeCommandHandler-client.md): Runs the handlers client scripts registered for a command, as if it had been typed.
