Struct Voice
zaun_bot::Voice · Struct
pub struct VoiceThe bot’s voice: one stay at a time.
Methods
Section titled “Methods”pub fn seek(ms: u64) -> Result<(), HostError>Jumps to ms into the current track; past the end, the track ends.
Errors
Section titled “Errors”UNSUPPORTED for live streams and pushed audio, and on hosts that cannot seek;
CONFLICT when nothing plays.
set_volume
Section titled “set_volume”pub fn set_volume(percent: u16) -> Result<(), HostError>Sets the playback volume, 0–200 % (100 when the bot joins).
Errors
Section titled “Errors”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.
remove
Section titled “remove”pub fn remove(index: u32) -> Result<Option<String>, HostError>Removes the queued track at index (0 plays next); returns its title.
Errors
Section titled “Errors”NOT_FOUND past the end of the queue; UNSUPPORTED on hosts without queue control.
move_track
Section titled “move_track”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.
Errors
Section titled “Errors”NOT_FOUND past the end of the queue; UNSUPPORTED on hosts without queue control.
shuffle
Section titled “shuffle”pub fn shuffle() -> Result<(), HostError>Puts the queue in a random order; the current track keeps playing.
Errors
Section titled “Errors”UNSUPPORTED on hosts without queue control.
clear_queue
Section titled “clear_queue”pub fn clear_queue() -> Result<(), HostError>Empties the queue; unlike Voice::stop, the current track keeps playing.
Errors
Section titled “Errors”UNSUPPORTED on hosts without queue control.
set_loop
Section titled “set_loop”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.
Errors
Section titled “Errors”UNSUPPORTED on hosts without looping.
pub fn join(channel: &str) -> Result<(), HostError>Joins voice channel channel (leaving another one); returns once audio can flow.
Errors
Section titled “Errors”NOT_GRANTED without the voice capability; FORBIDDEN without CONNECT/SPEAK.
pub fn leave()Leaves; playback stops and the queue is cleared.
play_url
Section titled “play_url”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.
Errors
Section titled “Errors”CONFLICT when not in a voice channel; an address outside the grants shows up as a
TrackError event when the track starts.
enqueue_url
Section titled “enqueue_url”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.
Errors
Section titled “Errors”As Voice::play_url; CONFLICT with limit_reached past 100 tracks.
play_ogg
Section titled “play_ogg”pub fn play_ogg(bytes: Vec<u8>, title: Option<&str>) -> Result<(), HostError>Plays Ogg Opus bytes (≤ 16 MiB) now.
Errors
Section titled “Errors”As Voice::play_url.
start_stream
Section titled “start_stream”pub fn start_stream(title: Option<&str>) -> Result<(), HostError>Starts a track the bot feeds with Voice::push_opus until Voice::end_stream.
Errors
Section titled “Errors”As Voice::play_url.
push_opus
Section titled “push_opus”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.
Errors
Section titled “Errors”BUSY past 3 s buffered (push again later); CONFLICT without a stream track.
end_stream
Section titled “end_stream”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.
resume
Section titled “resume”pub fn resume()Resumes.
pub fn state() -> VoiceStateWhere the bot is and what it plays.
Trait implementations
Section titled “Trait implementations”Clone, Copy, Debug, Default