Skip to content

zaun_bot::Voice · Struct

pub struct Voice

The bot’s voice: one stay at a time.

pub fn seek(ms: u64) -> Result<(), HostError>

Jumps to ms into the current track; past the end, the track ends.

UNSUPPORTED for live streams and pushed audio, and on hosts that cannot seek; CONFLICT when nothing plays.

pub fn set_volume(percent: u16) -> Result<(), HostError>

Sets the playback volume, 0–200 % (100 when the bot joins).

BAD_REQUEST (detail percent) above 200, checked before the call; UNSUPPORTED on hosts without an Opus encoder, which is most of them for now: tell the member and go on.

pub fn remove(index: u32) -> Result<Option<String>, HostError>

Removes the queued track at index (0 plays next); returns its title.

NOT_FOUND past the end of the queue; UNSUPPORTED on hosts without queue control.

pub fn move_track(from: u32, to: u32) -> Result<(), HostError>

Moves the queued track at from to to (both 0-based); the tracks between shift.

NOT_FOUND past the end of the queue; UNSUPPORTED on hosts without queue control.

pub fn shuffle() -> Result<(), HostError>

Puts the queue in a random order; the current track keeps playing.

UNSUPPORTED on hosts without queue control.

pub fn clear_queue() -> Result<(), HostError>

Empties the queue; unlike Voice::stop, the current track keeps playing.

UNSUPPORTED on hosts without queue control.

pub fn set_loop(mode: LoopMode) -> Result<(), HostError>

Sets what happens when a track ends: go on, repeat it, or requeue it at the end.

UNSUPPORTED on hosts without looping.

pub fn join(channel: &str) -> Result<(), HostError>

Joins voice channel channel (leaving another one); returns once audio can flow.

NOT_GRANTED without the voice capability; FORBIDDEN without CONNECT/SPEAK.

pub fn leave()

Leaves; playback stops and the queue is cleared.

pub fn play_url(url: &str, title: Option<&str>) -> Result<(), HostError>

Plays an Ogg Opus file or stream now, replacing the current track: an https:// URL on a network host, or an http:///https:// URL on a local_network address. The SDK passes the URL through; the host checks it.

CONFLICT when not in a voice channel; an address outside the grants shows up as a TrackError event when the track starts.

pub fn enqueue_url(url: &str, title: Option<&str>) -> Result<u32, HostError>

Queues an Ogg Opus file or stream (as Voice::play_url); returns the queue’s length.

As Voice::play_url; CONFLICT with limit_reached past 100 tracks.

pub fn play_ogg(bytes: Vec<u8>, title: Option<&str>) -> Result<(), HostError>

Plays Ogg Opus bytes (≤ 16 MiB) now.

As Voice::play_url.

pub fn start_stream(title: Option<&str>) -> Result<(), HostError>

Starts a track the bot feeds with Voice::push_opus until Voice::end_stream.

As Voice::play_url.

pub fn push_opus(packets: &[Vec<u8>]) -> Result<u32, HostError>

Opus packets (2.5–120 ms each, ≤ 1000 bytes) for the current stream; returns the ms buffered. Push about as fast as it plays.

BUSY past 3 s buffered (push again later); CONFLICT without a stream track.

pub fn end_stream()

Ends the stream track once its buffered packets have played.

pub fn skip()

Ends the current track; the next queued one starts.

pub fn stop()

Ends the current track and clears the queue.

pub fn pause()

Pauses.

pub fn resume()

Resumes.

pub fn state() -> VoiceState

Where the bot is and what it plays.

Clone, Copy, Debug, Default

Full rustdoc page