Members, roles and moderation
Members and roles
Section titled “Members and roles”The cache has the community’s roles and channels, and the members it has seen. Fetch the full member list when you need it:
const members = await community.members.fetch();const mods = await community.roles.create("Moderators", { permissions: ["KickMembers", "TimeoutMembers"] });await members.first().roles.add(mods);let members = community.fetch_members()?;let mods = community.create_role("Moderators", Permissions::KICK_MEMBERS | Permissions::TIMEOUT_MEMBERS)?;members[0].add_role(&mods)?;Checking permissions
Section titled “Checking permissions”if (member.permissions(channel).has("SendMessages")) { /* … */ }use zaun_client::protocol::bits::Permissions;
if author.can(Permissions::SEND_MESSAGES, Some(message.channel())) { /* … */ }This uses the same resolver as the host, applied to the cache. Use it to hide what a member can’t do; the host still decides (it also applies lockdowns and newcomer rules).
Moderation
Section titled “Moderation”await target.timeout(10 * 60_000, "cool down");await target.kick("asked to");await target.ban("spam");use std::time::Duration;
target.timeout(Some(Duration::from_secs(600)), Some("cool down"))?;target.kick(Some("asked to"))?;target.ban(Some("spam"))?;Each needs the matching permission (TIMEOUT_MEMBERS, KICK_MEMBERS, BAN_MEMBERS) and a highest
role above the target’s. Nobody can act on the owner. Bans follow the member’s key, so a banned
member can’t come back with the same identity.
Invites and channels
Section titled “Invites and channels”const link = await community.createInvite({ maxUses: 5, expiresIn: 86_400 });const lounge = await community.channels.create("lounge", { type: "voice" });use zaun_client::protocol::model::ChannelKind;
let link = community.create_invite(5, Some(Duration::from_secs(86_400)))?; // 5 uses, one daylet lounge = community.create_channel("lounge", ChannelKind::Voice)?;