Skip to main content

Voice

Struct Voice 

Source
pub struct Voice;
Expand description

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

Implementations§

Source§

impl Voice

Source

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

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

§Errors

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

Source

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

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

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

Source§

impl Voice

Source

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

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

§Errors

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

Source

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

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

Source

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

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

§Errors

UNSUPPORTED on hosts without queue control.

Source

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

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

§Errors

UNSUPPORTED on hosts without queue control.

Source

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

UNSUPPORTED on hosts without looping.

Source§

impl Voice

Source

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

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

§Errors

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

Source

pub fn leave()

Leaves; playback stops and the queue is cleared.

Source

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

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

Source

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

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

Source

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

Plays Ogg Opus bytes (≤ 16 MiB) now.

§Errors

As Voice::play_url.

Source

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

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

§Errors

As Voice::play_url.

Source

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

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

Source

pub fn end_stream()

Ends the stream track once its buffered packets have played.

Source

pub fn skip()

Ends the current track; the next queued one starts.

Source

pub fn stop()

Ends the current track and clears the queue.

Source

pub fn pause()

Pauses.

Source

pub fn resume()

Resumes.

Source

pub fn state() -> VoiceState

Where the bot is and what it plays.

Trait Implementations§

Source§

impl Clone for Voice

Source§

fn clone(&self) -> Voice

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Voice

Source§

impl Debug for Voice

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Voice

Source§

fn default() -> Voice

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Voice

§

impl RefUnwindSafe for Voice

§

impl Send for Voice

§

impl Sync for Voice

§

impl Unpin for Voice

§

impl UnsafeUnpin for Voice

§

impl UnwindSafe for Voice

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.