# Struct Context

> The interaction being handled, without its data (handlers get the data separately).

`zaun_bot::Context` · Struct

```rust
pub struct Context { … }
```

The interaction being handled, without its data (handlers get the data separately).

The first answer must be one of `reply`,
`reply_ephemeral`, `respond`,
`defer`, `defer_update`,
`update_message` or `show_modal`, within 3 s.
After it, use `followup` and `edit_original` for
15 minutes.

## Fields

### `id: Id`

The interaction id.

### `bot_id: Id`

The bot's id in this community.

### `channel_id: Id`

The channel it happened in.

### `member: Member`

Who triggered it.

### `app_permissions: u64`

The bot's effective permissions in the channel.

### `locale: Option<String>`

The invoker's locale (BCP 47), if their client sent one.

### `message: Option<Message>`

For component interactions: the message holding the component.

### `created_at: u64`

When the host received it (ms).

## Methods

### `split`

```rust
pub fn split(i: Interaction) -> (Self, InteractionData)
```

Splits an interaction into its context and data.

### `respond`

```rust
pub fn respond(&self, response: Response) -> Result<Option<Id>, HostError>
```

Sends any initial `Response`. Returns the created message id, if any.

# Errors
The host's refusal (already answered, too late, a message the bot may not send).

### `reply`

```rust
pub fn reply<impl Into<Reply>>(&self, reply: impl Into<Reply>) -> Result<Option<Id>, HostError>
```

Answers with a message in the channel.

# Errors
See `respond`.

### `reply_ephemeral`

```rust
pub fn reply_ephemeral<impl Into<Reply>>(&self, reply: impl Into<Reply>) -> Result<Option<Id>, HostError>
```

Answers with a message only the invoker sees.

# Errors
See `respond`.

### `defer`

```rust
pub fn defer(&self, ephemeral: bool) -> Result<Option<Id>, HostError>
```

Shows "thinking…" and buys 15 minutes; finish with `edit_original`.

# Errors
See `respond`.

### `defer_update`

```rust
pub fn defer_update(&self) -> Result<Option<Id>, HostError>
```

Acknowledges a component click without changing anything yet.

# Errors
See `respond`.

### `update_message`

```rust
pub fn update_message<impl Into<Reply>>(&self, reply: impl Into<Reply>) -> Result<Option<Id>, HostError>
```

Replaces the message holding the clicked component (it must be the bot's).

# Errors
See `respond`.

### `show_modal`

```rust
pub fn show_modal<impl Into<Modal>>(&self, modal: impl Into<Modal>) -> Result<Option<Id>, HostError>
```

Opens a modal for the invoker. Not allowed in answer to a modal submit.

# Errors
See `respond`.

### `followup`

```rust
pub fn followup<impl Into<Reply>>(&self, reply: impl Into<Reply>) -> Result<Option<Id>, HostError>
```

Sends a follow-up message (at most 10).

# Errors
The host's refusal.

### `edit_original`

```rust
pub fn edit_original<impl Into<Reply>>(&self, reply: impl Into<Reply>) -> Result<(), HostError>
```

Replaces the original response.

# Errors
The host's refusal.

### `delete_original`

```rust
pub fn delete_original(&self) -> Result<(), HostError>
```

Deletes the original response.

# Errors
The host's refusal.

### `dm`

```rust
pub fn dm<impl Into<Reply>>(&self, member_id: &str, reply: impl Into<Reply>) -> Result<(Id, Id), HostError>
```

Sends a direct message to a member (capability `dms`), for example the invoker:
`ctx.dm(&ctx.member.member_id, "details")`. Returns the DM's channel id and the
message id.

# Errors
The host's refusal (`FORBIDDEN` with reason `dms_closed` when the member does not take
DMs from bots).

### `set_presence`

```rust
pub fn set_presence<impl Into<Option<crate::presence::Activity>>>(&self, status: Status, activity: impl Into<Option<Activity>>)
```

Sets the bot's status and activity (`crate::presence::set`).

### `set_status_text`

```rust
pub fn set_status_text<impl Into<String>>(&self, text: impl Into<String>) -> Result<(), HostError>
```

Sets the bot's custom status text (`crate::presence::set_status_text`).

# Errors
The host's refusal.

## Trait implementations

`Clone`, `Debug`

[Full rustdoc page](/docs/api/rust/zaun-bot/zaun_bot/context/struct.Context.html)
