# Struct Community

> A community this client belongs to (or did: a handle outlives a leave).

`zaun_client::Community` · Struct

```rust
pub struct Community { … }
```

A community this client belongs to (or did: a handle outlives a leave).

## Methods

### `dms`

```rust
pub fn dms(&self) -> Vec<Channel>
```

This member's open DMs, from the cache.

### `fetch_dms`

```rust
pub fn fetch_dms(&self) -> Result<Vec<Channel>>
```

Reloads the open DMs from the host.

# Errors
The host refused or did not answer.

### `dm_settings`

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

This member's DM setting.

# Errors
The host refused or did not answer.

### `set_dms_from_bots`

```rust
pub fn set_dms_from_bots(&self, allow: bool) -> Result<DmSettings>
```

Lets bots open DMs with this member (`true`), or not.

# Errors
The host refused or did not answer.

### `presences`

```rust
pub fn presences(&self) -> Vec<Presence>
```

The presence of every member who is not offline.

### `set_status_text`

```rust
pub fn set_status_text(&self, text: Option<&str>, emoji: Option<&str>, expires_at: Option<u64>) -> Result<MemberData>
```

Sets this member's custom status here (text, emoji, and when the host clears it, ms);
`None` for both text and emoji clears it. Everyone else gets a member update.

# Errors
The host's refusal (`PAYLOAD_TOO_LARGE` past 128 characters, `BAD_REQUEST`), or a
connection error.

### `commands`

```rust
pub fn commands(&self) -> Vec<ApplicationCommand>
```

Every bot command in the community, as last heard (each with its `bot_id`).

### `bots`

```rust
pub fn bots(&self) -> Vec<BotCard>
```

The installed bots' public cards, as last heard.

### `fetch_bots`

```rust
pub fn fetch_bots(&self) -> Result<Vec<BotCard>>
```

Asks the host for every bot's card (owners also get each bot's full request).

# Errors
The host refused or did not answer.

### `bot`

```rust
pub fn bot(&self, bot: BotId) -> Result<BotCard>
```

Asks the host for one bot's card.

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

### `install_bot`

```rust
pub fn install_bot(&self, package: AttachmentId, grants: Option<GrantChoice>, role_position: Option<u32>) -> Result<BotCard>
```

Owner only: installs the `.zbot` package uploaded as `package` (an attachment not on
a message). `grants` absent: everything the manifest asks for, within the host's ceiling.

# Errors
The host refused (not the owner, a bad package, over the ceiling) or did not answer.

### `update_bot`

```rust
pub fn update_bot(&self, bot: BotId, package: AttachmentId) -> Result<BotCard>
```

Owner only: updates a bot to a newer package of the same publisher.

# Errors
As `install_bot`.

### `grant_bot`

```rust
pub fn grant_bot(&self, bot: BotId, permissions: Option<Permissions>, capabilities: Option<Capabilities>) -> Result<BotCard>
```

Owner only: replaces a bot's grants (approves a waiting update when it covers it).

# Errors
The host refused or did not answer.

### `enable_bot`

```rust
pub fn enable_bot(&self, bot: BotId) -> Result<BotCard>
```

Owner only: starts a disabled bot.

# Errors
The host refused or did not answer.

### `disable_bot`

```rust
pub fn disable_bot(&self, bot: BotId) -> Result<BotCard>
```

Owner only: stops a bot and hides its commands.

# Errors
The host refused or did not answer.

### `remove_bot`

```rust
pub fn remove_bot(&self, bot: BotId, keep_data: bool) -> Result<()>
```

Owner only: removes a bot, its role and commands (and its data unless `keep_data`).

# Errors
The host refused or did not answer.

### `register_bot`

```rust
pub fn register_bot(&self, member: &Member, name: Option<&str>) -> Result<BotCard>
```

Owner only: marks `member` (a client connected over SimpleX) as an external bot.

# Errors
The host refused or did not answer.

### `set_commands`

```rust
pub fn set_commands(&self, commands: Vec<ApplicationCommand>) -> Result<Vec<ApplicationCommand>>
```

As a bot: replaces this bot's whole command list; answers it with the host's ids.

# Errors
The host refused (this member is not a bot, a command breaks the rules).

### `configure_bot`

```rust
pub fn configure_bot<K, V, impl IntoIterator<Item = (K, Option<V>)>>(&self, bot: BotId, values: impl IntoIterator<Item = (K, Option<V>)>) -> Result<BTreeMap<String, String>>
```

Owner only: sets (`Some`) or clears (`None`, back to the default) the values of the
settings `bot`'s manifest declares (its card's `config`), and answers every value the
owner has set, a secret one as `"••••"` (`MASKED`).
The bot gets them at once. Keys are `[a-z][a-z0-9_]{0,63}`, values ≤ 4 KiB, ≤ 32 of
each.

# Errors
A malformed key or value (`Error::Protocol`), or the host
refused: `FORBIDDEN` (not the owner), `NOT_FOUND` (no such bot), `BAD_REQUEST` with
field `config.<key>` (a key the manifest does not declare). Needs zaun-host 0.4.0.

### `bot_config`

```rust
pub fn bot_config(&self, bot: BotId) -> Result<BTreeMap<String, String>>
```

Owner only: the values set for `bot`'s settings, a secret one as `"••••"`; a key
not here uses its card's `default`.

# Errors
As `configure_bot`.

### `install_bot_from`

```rust
pub fn install_bot_from(&self, package: AttachmentId, grants: Option<GrantChoice>, role_position: Option<u32>, source: InstallSource) -> Result<BotCard>
```

Owner only: `install_bot` with the registry `source` the package
was verified against: the uploaded `catalog.json`, its signature and, for a version not
in the catalog's `latest`, the uploaded history file. The host checks the source
offline against its own registry keys; one that does not verify installs as `direct`.

# Errors
As `install_bot`, and `BAD_REQUEST` for a source that repeats an
attachment or has a blank signature.

### `update_bot_from`

```rust
pub fn update_bot_from(&self, bot: BotId, package: AttachmentId, source: InstallSource) -> Result<BotCard>
```

Owner only: `update_bot` with the registry `source` the new package
was verified against, as for `install_bot_from`.

# Errors
As `install_bot_from`.

### `id`

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

Its id.

### `data`

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

A copy of the cache: the whole community as plain data, or `None` when this client
does not belong to it (any more).

### `name`

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

Its name, from the descriptor the host's welcome proved (empty before).

### `description`

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

Its description, from the same descriptor.

### `is_owner`

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

Whether this client owns it.

### `me`

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

This client as a member of it.

### `channels`

```rust
pub fn channels(&self) -> Vec<Channel>
```

Its channels and categories this member can see, in order.

### `channel_by_name`

```rust
pub fn channel_by_name(&self, name: &str) -> Option<Channel>
```

The first channel named `name` (names are not unique).

### `channel`

```rust
pub fn channel(&self, id: ChannelId) -> Channel
```

The channel `id`, known to the cache or not.

### `roles`

```rust
pub fn roles(&self) -> Vec<Role>
```

Its roles, highest first.

### `role_by_name`

```rust
pub fn role_by_name(&self, name: &str) -> Option<Role>
```

The first role named `name`.

### `role`

```rust
pub fn role(&self, id: RoleId) -> Role
```

The role `id`, known to the cache or not.

### `members`

```rust
pub fn members(&self) -> Vec<Member>
```

The members the cache has heard of; `fetch_members` loads them
all.

### `member`

```rust
pub fn member(&self, id: MemberId) -> Member
```

The member `id`, known to the cache or not.

### `fetch_members`

```rust
pub fn fetch_members(&self) -> Result<Vec<Member>>
```

Loads every member into the cache.

# Errors
The host refused or did not answer.

### `create_channel`

```rust
pub fn create_channel(&self, name: &str, kind: ChannelKind) -> Result<Channel>
```

Makes a channel of `kind` named `name`.

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

### `create_channel_in`

```rust
pub fn create_channel_in(&self, parent: &Channel, name: &str, kind: ChannelKind) -> Result<Channel>
```

Makes a channel of `kind` named `name` inside the category `parent`.

# Errors
As `create_channel`.

### `create_role`

```rust
pub fn create_role(&self, name: &str, permissions: Permissions) -> Result<Role>
```

Makes a role named `name` with `permissions`.

# Errors
The host refused (no `MANAGE_ROLES`, or permissions this member lacks) or did not
answer.

### `create_invite`

```rust
pub fn create_invite(&self, max_uses: u32, expires_in: Option<Duration>) -> Result<String>
```

Makes an invitation link for `max_uses` joins (0: no limit), expiring after
`expires_in` if given. The link is a secret: give it only to who should join.

# Errors
The host refused or did not answer.

### `leave`

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

Leaves the community (the owner cannot). Once the host accepts, it is forgotten here:
its state and member key leave the store, `Event::CommunityDelete`
follows with `RemovalReason::Left`, and a later `Client::join`
of it starts afresh.

# Errors
The host refused or did not answer.

### `hand_off`

```rust
pub fn hand_off(&self, host_address: &str, host_key: PublicKey) -> Result<HandOff>
```

As the owner, hands the community to the host at `host_address` whose key is
`host_key`; see `HandOff`.

# Errors
This client does not hold the root key, the host refused, or no answer came.

### `follow`

```rust
pub fn follow(&self, host_address: &str, host_key: PublicKey) -> Result<HostId>
```

Follows the community to the host the owner named, when no descriptor update arrived.

# Errors
The new host refused this member, or a timeout.

### `voice_channels`

```rust
pub fn voice_channels(&self) -> Vec<Channel>
```

This member's voice channels.

## Trait implementations

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

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