# Trait Bot

> A Zaun bot. Every handler has a no-op default; implement the ones you need.

`zaun_bot::Bot` · Trait

```rust
pub trait Bot { … }
```

A Zaun bot. Every handler has a no-op default; implement the ones you need.

The host calls one handler at a time, so `&mut self` state is safe. State lives only as
long as the instance; use `crate::storage` for anything that must survive a restart.

Event handlers run only for events the manifest's `events` asks for (wire types such as
`message.created`, groups such as `messages`, `members`, `dms`, or `*`); see
`docs/events.md`. `on_ready` always runs first.

## Methods

### `on_start`

```rust
fn on_start(&mut self, config: &Config);
```

The bot started (each instance start, before `Bot::commands`): a good place to set
its presence (`crate::presence`).

### `on_config`

```rust
fn on_config(&mut self, config: &Config);
```

The owner changed the bot's configuration while it runs: every value again, as at
start. The bot is not restarted; refresh whatever it derived from the old values.

### `commands`

```rust
fn commands(&mut self, config: &Config) -> Vec<ApplicationCommand>;
```

The application commands to register when the bot starts.

### `on_command`

```rust
fn on_command(&mut self, ctx: Context, command: CommandData);
```

A slash, user or message command was used. Answer within 3 s (or call
`Context::defer`); the runtime defers automatically at 2.5 s.

### `on_component`

```rust
fn on_component(&mut self, ctx: Context, component: ComponentData);
```

A button was clicked or a select changed on one of the bot's messages.

### `on_modal`

```rust
fn on_modal(&mut self, ctx: Context, modal: ModalData);
```

A modal the bot opened was submitted.

### `on_autocomplete`

```rust
fn on_autocomplete(&mut self, ctx: Context, command: CommandData) -> Vec<Choice>;
```

The invoker is typing in an option with `autocomplete`. Return up to 25 choices.

### `on_timer`

```rust
fn on_timer(&mut self, id: u64, tag: String);
```

A timer from `crate::timers` fired.

### `on_event`

```rust
fn on_event(&mut self, ctx: EventContext, event: Event);
```

Every event; the default calls the typed handlers below. Override it to see events
raw, before (or instead of) them.

### `on_ready`

```rust
fn on_ready(&mut self, ctx: EventContext, me: Ready);
```

The bot's connection is up: its ids and community. Always the first event.

### `on_message_create`

```rust
fn on_message_create(&mut self, ctx: EventContext, message: Message, is_dm: bool);
```

A message was posted (`messages`). `is_dm`: in a direct message with the bot.

### `on_message_update`

```rust
fn on_message_update(&mut self, ctx: EventContext, message: Message, is_dm: bool);
```

A message was edited (`messages`).

### `on_message_delete`

```rust
fn on_message_delete(&mut self, ctx: EventContext, channel_id: Id, message_id: Id);
```

A message was deleted (`messages`).

### `on_message_delete_bulk`

```rust
fn on_message_delete_bulk(&mut self, ctx: EventContext, channel_id: Id, ids: Vec<Id>);
```

Messages were deleted together, by a ban (`messages`).

### `on_reaction_add`

```rust
fn on_reaction_add(&mut self, ctx: EventContext, reaction: Reaction);
```

A reaction was added (`reactions`).

### `on_reaction_remove`

```rust
fn on_reaction_remove(&mut self, ctx: EventContext, reaction: Reaction);
```

A reaction was removed (`reactions`).

### `on_member_join`

```rust
fn on_member_join(&mut self, ctx: EventContext, member: Member);
```

A member joined (`members`, capability `members`).

### `on_member_update`

```rust
fn on_member_update(&mut self, ctx: EventContext, member: Member);
```

A member changed their name (`members`).

### `on_member_leave`

```rust
fn on_member_leave(&mut self, ctx: EventContext, member_id: Id);
```

A member left, was kicked or banned (`members`).

### `on_removed`

```rust
fn on_removed(&mut self, ctx: EventContext, reason: String);
```

The bot itself was removed (`kicked`, `banned`); it stops right after.

### `on_member_roles_update`

```rust
fn on_member_roles_update(&mut self, ctx: EventContext, roles: MemberRoles);
```

A member's roles changed (`members`).

### `on_member_timeout`

```rust
fn on_member_timeout(&mut self, ctx: EventContext, timeout: MemberTimeout);
```

A member was timed out, or their timeout cleared (`members`).

### `on_channel_create`

```rust
fn on_channel_create(&mut self, ctx: EventContext, channel: Channel);
```

A channel the bot can see was created (`channels`).

### `on_channel_update`

```rust
fn on_channel_update(&mut self, ctx: EventContext, channel: Channel);
```

A channel changed (`channels`).

### `on_channel_delete`

```rust
fn on_channel_delete(&mut self, ctx: EventContext, channel_id: Id);
```

A channel was deleted, or the bot lost access (`channels`).

### `on_role_create`

```rust
fn on_role_create(&mut self, ctx: EventContext, role: Role);
```

A role was created (`roles`).

### `on_role_update`

```rust
fn on_role_update(&mut self, ctx: EventContext, role: Role);
```

A role changed (`roles`).

### `on_role_delete`

```rust
fn on_role_delete(&mut self, ctx: EventContext, role_id: Id);
```

A role was deleted (`roles`).

### `on_typing_start`

```rust
fn on_typing_start(&mut self, ctx: EventContext, typing: Typing);
```

Members are typing in a channel the bot can see (`typing`).

### `on_presence_update`

```rust
fn on_presence_update(&mut self, ctx: EventContext, presence: Presence);
```

A member's presence changed (`presence`, capability `presence`).

### `on_community_update`

```rust
fn on_community_update(&mut self, ctx: EventContext, profile: CommunityProfile);
```

The community's settings changed (`community`).

### `on_commands_update`

```rust
fn on_commands_update(&mut self, ctx: EventContext, bot_id: Id);
```

A bot's command list changed (`commands`); its bot id.

### `on_dm_open`

```rust
fn on_dm_open(&mut self, ctx: EventContext, channel: Channel);
```

A DM with the bot was opened, by the bot or a member (`dms`, capability `dms`).

### `on_dm_close`

```rust
fn on_dm_close(&mut self, ctx: EventContext, channel_id: Id);
```

The bot closed a DM (`dms`).

### `on_raw`

```rust
fn on_raw(&mut self, ctx: EventContext, event: RawEvent);
```

An event without a typed handler: its wire type and JSON body.

### `on_voice_event`

```rust
fn on_voice_event(&mut self, event: VoiceEvent);
```

Something happened in the bot's voice stay or player (`crate::Voice`): a track
started, ended or failed, someone joined or left, or the stay ended.

[Full rustdoc page](/docs/api/rust/zaun-bot/zaun_bot/bot/trait.Bot.html)
