Skip to content

Struct Channel

zaun_client::Channel · Struct

pub struct Channel { … }

A channel or category of a community.

pub fn is_dm(&self) -> bool

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

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

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

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

Closes a DM for this member.

NOT_FOUND or no answer.

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.

Error::Closed when the client stopped.

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).

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.

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

pub fn typing_mode(&self) -> TypingMode

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

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.

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

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.

As invoke_command.

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.

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

pub const fn id(&self) -> ChannelId

Its id.

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

The community it belongs to.

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

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

pub fn name(&self) -> String

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

pub fn kind(&self) -> ChannelKind

Text when the cache does not have it.

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

Its topic.

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

The category it is in.

pub fn is_voice(&self) -> bool

Whether it is a voice (or stage) channel.

pub fn is_category(&self) -> bool

Whether it is a category.

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.

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.

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.

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

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).

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

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.

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

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

Deletes the channel or category.

The host refused or did not answer.

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

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

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.

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.

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

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

As join.

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

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

Clone, Debug, Display, PartialEq

Full rustdoc page