# Struct Channel

> A channel or category of a community.

`zaun_client::Channel` · Struct

```rust
pub struct Channel { … }
```

A channel or category of a community.

## Methods

### `is_dm`

```rust
pub fn is_dm(&self) -> bool
```

Whether it is a direct message, not a community channel.

### `recipient`

```rust
pub fn recipient(&self) -> Option<Member>
```

The other participant of a DM; `None` for a community channel.

### `close_dm`

```rust
pub fn close_dm(&self) -> Result<()>
```

Closes a DM for this member.

# Errors
`NOT_FOUND` or no answer.

### `start_typing`

```rust
pub fn start_typing(&self) -> Result<bool>
```

Tells the host this member is typing here; call it while the user types (the host
forwards at most one signal per member per channel per 3 s). Returns `false` without
sending anything in a channel whose typing is `off`.

# Errors
`Error::Closed` when the client stopped.

### `typing`

```rust
pub fn typing(&self) -> Option<TypingNow>
```

Who else is typing here now: members by id in a `named` channel, only how many in an
`anonymous` one; `None` when nobody is (or the channel's typing is `off`).

### `set_typing_mode`

```rust
pub fn set_typing_mode(&self, mode: TypingMode) -> Result<()>
```

Sets who sees typing here (`channel.update`, needs `MANAGE_CHANNELS`): `Named`,
`Anonymous` or `Off`. The cache follows with the host's `channel.updated`.

# Errors
`Error::Refused` (`FORBIDDEN` without the permission), or no
answer.

### `typing_mode`

```rust
pub fn typing_mode(&self) -> TypingMode
```

The channel's typing setting (`named` when the cache does not have it).

### `invoke_command`

```rust
pub fn invoke_command(&self, command: CommandId, options: Vec<OptionValue>, target: Option<String>) -> Result<InteractionId>
```

Runs a bot command here. `target` is the member (user command) or message (message
command) acted on, base64url. The bot's answer arrives as an event.

# Errors
The host refused (no `USE_APPLICATION_COMMANDS`, bad options) or did not answer.

### `autocomplete`

```rust
pub fn autocomplete(&self, command: CommandId, options: Vec<OptionValue>) -> Result<InteractionId>
```

Asks the bot for suggestions for the option marked `focused`; they arrive as
`Event::Autocomplete`.

# Errors
As `invoke_command`.

### `submit_modal`

```rust
pub fn submit_modal(&self, modal: InteractionId, custom_id: &str, components: Vec<SubmittedInput>) -> Result<InteractionId>
```

Submits a modal a bot opened (`Event::ModalOpen`): `modal`
is the interaction that opened it.

# Errors
The host refused (a required field missing, too late, submitted already).

### `id`

```rust
pub const fn id(&self) -> ChannelId
```

Its id.

### `community`

```rust
pub const fn community(&self) -> &Community
```

The community it belongs to.

### `data`

```rust
pub fn data(&self) -> Option<ChannelData>
```

The cache's copy, or `None` when the cache does not have it (any more).

### `name`

```rust
pub fn name(&self) -> String
```

Its name (empty when the cache does not have it).

### `kind`

```rust
pub fn kind(&self) -> ChannelKind
```

Text when the cache does not have it.

### `topic`

```rust
pub fn topic(&self) -> Option<String>
```

Its topic.

### `parent`

```rust
pub fn parent(&self) -> Option<Self>
```

The category it is in.

### `is_voice`

```rust
pub fn is_voice(&self) -> bool
```

Whether it is a voice (or stage) channel.

### `is_category`

```rust
pub fn is_category(&self) -> bool
```

Whether it is a category.

### `send`

```rust
pub fn send<impl Into<MessageOptions>>(&self, options: impl Into<MessageOptions>) -> Result<Message>
```

Posts a message: text (`channel.send("hi")`), or `MessageOptions` with embeds,
files and the message it answers. An embed's pictures and the files are uploaded
first, each once, over this member's post-quantum connection to the host.

# Errors
A broken embed or more than 10 files and pictures (`Error::Protocol`, before
anything is uploaded); embeds to a host that does not keep them
(`Error::Unsupported`); a failed upload; or the host refused (no `SEND_MESSAGES`,
`EMBED_LINKS` or `ATTACH_FILES`, slowmode, too long) or did not answer.

### `send_pending`

```rust
pub fn send_pending<impl Into<MessageOptions>>(&self, options: impl Into<MessageOptions>) -> Result<PendingMessage>
```

Posts like `send` but returns at once with the message as it will look,
so it can be shown before the host answers (it takes a relay round trip or two). The
outcome comes as `Event::MessageSent` or
`Event::MessageSendFailed` with the same
`pending` number. Text posts keep their order; a post
with files uploads them first and may land after text sent later.

# Errors
What `send` refuses before anything leaves (a broken embed, too many
files, a host without embeds), not yet a member, or the client stopped.

### `send_files`

```rust
pub fn send_files<impl AsRef<Path>>(&self, content: &str, paths: &[impl AsRef<Path>]) -> Result<Message>
```

Posts `content` with the files at `paths` attached (each uploaded first, over this
member's post-quantum connection to the host).

# Errors
A file the host would not take (too large, a file server it does not use), a failed
upload, or as `send`.

### `messages`

```rust
pub fn messages(&self, before: Option<u64>, limit: u32) -> Result<Vec<Message>>
```

Up to `limit` messages before sequence `before` (the newest without it), oldest first.

# Errors
The host refused (no `READ_MESSAGE_HISTORY`) or did not answer.

### `delete`

```rust
pub fn delete(&self) -> Result<()>
```

Deletes the channel or category.

# Errors
The host refused or did not answer.

### `participants`

```rust
pub fn participants(&self) -> Vec<VoiceParticipant>
```

Who is in this voice channel now (no key material).

### `join`

```rust
pub fn join(&self) -> Result<VoiceSession>
```

Joins this voice channel: relayed through the host's TURN server, every frame sealed
end to end. See `VoiceSession`.

# Errors
Not a voice channel, already in voice in this community, a host media policy this
client does not accept, no relay to be had, or the host refused.

### `join_with`

```rust
pub fn join_with(&self, options: VoiceOptions) -> Result<VoiceSession>
```

`join` with `options` (a direct path, joining muted or deafened).

# Errors
As `join`.

### `message`

```rust
pub fn message(&self, id: MessageId) -> PartialMessage
```

The message `id` in this channel, to act on without fetching it.

## Trait implementations

`Clone`, `Debug`, `Display`, `PartialEq`

[Full rustdoc page](/docs/api/rust/zaun-client/zaun_client/objects/struct.Channel.html)
