# Bots: remove() method

> The remove() method of the Bots interface removes a bot from the room, running onPlayerLeave for it.

The **`remove()`** method of the [`Bots`](/docs/room/bots) interface removes a bot from the room, running `onPlayerLeave` for it before it returns.

## Syntax

```ts
remove(bot)
```

### Parameters

`bot`
: The [`Bot`](/docs/room/bot), or its player ID.

### Return value

`true` if the bot was removed, or `false` if it wasn't in the room.

## Description

`onPlayerLeave` runs with the bot's player ID. Until the hook first awaits, the bot's presence entry is still there to read, no longer holding a seat; the presence ends before `remove()` returns. So code that cleans up after a player cleans up after bots too. `onLeave` doesn't run, since a bot has no connection.

While the room is under its [fill level](/docs/room/bots/fill), a removed bot is replaced by a new one.

## Examples

### Taking out an eliminated bot

```ts
// last-standing.ts
import { defineRoom, defineSchema, entity, isBot } from "@irtio/room";

const Fighter = entity("fighter", { owner: "string", hp: "u8" }, { key: "owner" });

export default defineRoom({
  tickRate: 10,
  schema: defineSchema({ entities: [Fighter] }),
  bots: {
    brawler: {
      start(room, bot) {
        if (!room.entities.get(Fighter, bot.player)) room.entities.create(Fighter, { owner: bot.player, hp: 100 });
      },
    },
  },
  onTick(room) {
    for (const fighter of room.entities.all(Fighter)) {
      if (fighter.hp === 0 && isBot(fighter.owner)) room.bots.remove(fighter.owner);
    }
  },
  onPlayerLeave(room, player) {
    const fighter = room.entities.get(Fighter, player);
    if (fighter) room.entities.delete(fighter);
  },
});
```

## See also

- [`Bots.add()`](/docs/room/bots/add)
- [`onPlayerLeave()`](/docs/room/room-definition/onplayerleave)
