# sm.game.bindChatCommand

Binds a chat command to a callback function. The callback function receives an array of parameters. The first parameter is the command itself.

**Kind:** Function

**Environments:** Game

## Game

``` { .lua .api-signature }
sm.game.bindChatCommand( command, params, callback, help )
```

[Open the full Game reference](../Game-Script-Environment/Static-Functions/sm.game.md#bindchatcommand)

Example:

```lua
sm.game.bindChatCommand( "/enable_client_toilet",
						 { { "bool", "enabled", false } },
						 "onChatCommand",
						 "Enables or disables client toilet." )
```

```lua
function MyGameScript.onChatCommand( self, params )
	if params[1] == "/enable_client_toilet" then
		self.settings.enable_client_toilet = params[2]
	end
end
```

**Parameters:**

| Name | Type | Description |
| --- | --- | --- |
| `command` | string | The command. |
| `params` | table | An array of parameters the callback function expects in the form of \{ \{ type, name (, optional, autocomplete ) \}, ... \}. The first is the <strong>type</strong> name of the parameter as a string. Valid types are "bool", "int", "number" and "string". The second is the <strong>name</strong> in the help text. Defaults to automatic naming ("p1", "p2", "p3", ...). The third is a bool value where true means that this parameter is <strong>optional</strong> (Optional, defaults to false). The fourth is a list of values that can be auto-completed to by pressing tab (Optional). |
| `callback` | string | The name of the Lua function to bind. |
| `help` | string | Help text. |
