# Bots: add() method

> The add() method of the Bots interface adds a bot running a behaviour the room declares, and runs its start hook.

The **`add()`** method of the [`Bots`](/docs/room/bots) interface adds a bot running a behaviour the room declares, and runs the behaviour's `start` before it returns.

## Syntax

```ts
add(behaviour)
add(behaviour, options)
```

### Parameters

`behaviour`
: The name of a behaviour in the room definition's `bots`.

`options` Optional
: An object with any of these properties:

  `name`
  : The bot's presence name, at most 64 characters. Defaults to `""`.

  `status`
  : The bot's presence status, JSON of at most 1,024 bytes. Defaults to `null`.

  `data`
  : The bot's [`data`](/docs/room/bot), a JSON object of at most 4,096 bytes. Defaults to `{}`.

### Return value

The new [`Bot`](/docs/room/bot).

### Exceptions

`Error`
: Thrown if the room declares no behaviour of that name.

`RangeError`
: Thrown if the room already holds `MAX_BOTS` (64) bots, or if people and bots already fill `room.maxPlayers` seats.

`TypeError` or `RangeError`
: Thrown if `name`, `status` or `data` isn't the type described above, or is over its limit.

## Description

The bot gets the player ID `bot:` and the next number, and is in presence at once, holding a seat. `onJoin` doesn't run for it. If `start` throws or returns a promise, the error is logged and the bot is removed again.

A bot `add()` puts over a [fill level](/docs/room/bots/fill) stays until a person's join or a `fill()` call removes it.

## Examples

### An opponent for a player alone

```ts
// duel.ts
import { defineRoom, isBot } from "@irtio/room";

export default defineRoom({
  bots: { duelist: {} },
  onJoin(room) {
    const people = [...room.presence].filter((entry) => !isBot(entry.player));
    if (people.length === 1 && room.bots.size === 0) room.bots.add("duelist", { name: "Training dummy", status: { ready: true } });
  },
});
```

## See also

- [`Bots.remove()`](/docs/room/bots/remove)
- [`Bots.fill()`](/docs/room/bots/fill)
- [A bot](/docs/room/guides/bots#a-bot)
