[][src]Struct serenity::voice::Handler

pub struct Handler {
    pub channel_id: Option<ChannelId>,
    pub endpoint: Option<String>,
    pub guild_id: GuildId,
    pub self_deaf: bool,
    pub self_mute: bool,
    pub session_id: Option<String>,
    pub token: Option<String>,
    pub user_id: UserId,
    // some fields omitted
}

The handler is responsible for "handling" a single voice connection, acting as a clean API above the inner connection.

Look into the Manager for a slightly higher-level interface for managing the existence of handlers.

Note: You should not manually mutate any struct fields. You should only read them. Use methods to mutate them.

Examples

Assuming that you already have a Manager, most likely retrieved via a Shard, you can join a guild's voice channel and deafen yourself like so:

This example is not tested
// assuming a `manager` has already been bound, hopefully retrieved through
// a websocket's connection.
use serenity::model::{ChannelId, GuildId};

let guild_id = GuildId(81384788765712384);
let channel_id = ChannelId(85482585546833920);

let handler = manager.join(Some(guild_id), channel_id);
handler.deafen(true);

Fields

The ChannelId to be connected to, if any.

Note: This must not be manually mutated. Call switch_to to mutate this value.

The voice server endpoint.

The Id of the guild to be connected to.

Whether the current handler is set to deafen voice connections.

Note: This must not be manually mutated. Call deafen to mutate this value.

Whether the current handler is set to mute voice connections.

Note: This must not be manually mutated. Call mute to mutate this value.

The session Id of the current voice connection, if any.

Note: This should be set through an update_state call.

The token of the current voice connection, if any.

Note: This should be set through an update_server call.

The Id of the current user.

This is configured via new or standalone.

Methods

impl Handler
[src]

Creates a new, standalone Handler which is not connected to the primary WebSocket to the Gateway.

Actions such as muting, deafening, and switching channels will not function through this Handler and must be done through some other method, as the values will only be internally updated.

For most use cases you do not want this. Only use it if you are using the voice component standalone from the rest of the library.

Connects to the voice channel if the following are present:

If they are all present, then true is returned. Otherwise, false is.

This will automatically be called by update_server or update_state when all three values become present.

Sets whether the current connection to be deafened.

If there is no live voice connection, then this only acts as a settings update for future connections.

Note: Unlike in the official client, you can be deafened while not being muted.

Note: If the Handler was created via standalone, then this will only update whether the connection is internally deafened.

Connect - or switch - to the given voice channel by its Id.

Leaves the current voice channel, disconnecting from it.

This does not forget settings, like whether to be self-deafened or self-muted.

Note: If the Handler was created via standalone, then this will only update whether the connection is internally connected to a voice channel.

Sets a receiver, i.e. a way to receive audio. Most use cases for bots do not require this.

The receiver argument can be thought of as an "optional Option". You can pass in just a boxed receiver, and do not need to specify Some.

Pass None to drop the current receiver, if one exists.

Sets whether the current connection is to be muted.

If there is no live voice connection, then this only acts as a settings update for future connections.

Note: If the Handler was created via standalone, then this will only update whether the connection is internally muted.

Plays audio from a source.

This can be a source created via voice::ffmpeg or voice::ytdl.

Plays audio from a source, returning the locked audio source.

Plays audio from a source.

Unlike play or play_returning, this stops all other sources attached to the channel.

Stops playing audio from a source, if one is set.

Switches the current connected voice channel to the given channel_id.

This has 3 separate behaviors:

  • if the given channel_id is equivalent to the current connected channel_id, then do nothing;
  • if the given channel_id is not equivalent to the current connected channel_id, then switch to the given channel_id;
  • if not currently connected to a voice channel, connect to the given one.

If you are dealing with switching from one group to another, then open another handler, and optionally drop this one via Manager::remove.

Note: The given channel_id, if in a guild, must be in the current handler's associated guild.

Note: If the Handler was created via standalone, then this will only update whether the connection is internally switched to a different channel.

Updates the voice server data.

You should only need to use this if you initialized the Handler via standalone.

Refer to the documentation for connect for when this will automatically connect to a voice channel.

Updates the internal voice state of the current user.

You should only need to use this if you initialized the Handler via standalone.

refer to the documentation for connect for when this will automatically connect to a voice channel.

Trait Implementations

impl Clone for Handler
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Drop for Handler
[src]

Leaves the current connected voice channel, if connected to one, and forgets all configurations relevant to this Handler.

impl Debug for Handler
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl Send for Handler

impl !Sync for Handler

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T> From for T
[src]

Performs the conversion.

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Borrow for T where
    T: ?Sized
[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut for T where
    T: ?Sized
[src]

Mutably borrows from an owned value. Read more

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

🔬 This is a nightly-only experimental API. (get_type_id)

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more

impl<T> Erased for T

impl<T> Typeable for T where
    T: Any

Get the TypeId of this object.

impl<T> DebugAny for T where
    T: Any + Debug
[src]

impl<T> CloneAny for T where
    T: Clone + Any
[src]

impl<T> UnsafeAny for T where
    T: Any