Struct twilight_lavalink::client::Lavalink[][src]

pub struct Lavalink(_);

The lavalink client that manages nodes, players, and processes events from Discord to tie it all together.

Note: You must call the process method with every Voice State Update and Voice Server Update event you receive from Discord. It will automatically forward these events to Lavalink. See its documentation for more information.

You can retrieve players using the player method. Players contain information about the active playing information of a guild and allows you to send events to the connected node, such as Play events.

Cloning

The client internally wraps its data within an Arc. This means that the client can be cloned and passed around tasks and threads cheaply.

Implementations

impl Lavalink[src]

pub fn new(user_id: UserId, shard_count: u64) -> Self[src]

Create a new Lavalink client instance.

The user ID and number of shards provided may not be modified during runtime, and the client must be re-created. These parameters are automatically passed to new nodes created via add.

See also new_with_resume, which allows you to specify session resume capability.

pub fn new_with_resume(
    user_id: UserId,
    shard_count: u64,
    resume: impl Into<Option<Resume>>
) -> Self
[src]

Like new, but allows you to specify resume capability (if any).

Provide None for the resume parameter to disable session resume capability. See the Resume documentation for defaults.

pub async fn process(&self, event: &Event) -> Result<(), ClientError>[src]

Process an event into the Lavalink client.

Note: calling this method in your event loop is required. See the crate documentation for an example.

This requires the VoiceServerUpdate and VoiceStateUpdate events that you receive from Discord over the gateway to send voice updates to nodes. For simplicity in some applications’ event loops, any event can be provided, but they will just be ignored.

The Ready event can optionally be provided to do some cleaning of stalled voice states that never received their voice server update half or vice versa. It is recommended that you process Ready events.

Errors

Returns ClientError::NodesUnconfigured if no nodes have been added to the client when attempting to retrieve a guild’s player.

pub async fn add(
    &self,
    address: SocketAddr,
    authorization: impl Into<String>
) -> Result<(Node, UnboundedReceiver<IncomingEvent>), NodeError>
[src]

Add a new node to be managed by the Lavalink client.

If a node already exists with the provided address, then it will be replaced.

pub async fn remove(&self, address: SocketAddr) -> Option<(SocketAddr, Node)>[src]

Remove a node from the list of nodes being managed by the Lavalink client.

The node is returned if it existed.

pub async fn best(&self) -> Result<Node, ClientError>[src]

Determine the “best” node for new players according to available nodes’ penalty scores.

Refer to Node::penalty for how this is calculated.

Errors

Returns ClientError::NodesUnconfigured if there are no configured nodes available in the client.

pub fn players(&self) -> &PlayerManager[src]

Retrieve an immutable reference to the player manager.

pub async fn player(
    &self,
    guild_id: GuildId
) -> Result<Ref<'_, GuildId, Player>, ClientError>
[src]

Retrieve a player for the guild.

Creates a player configured to use the best available node if a player for the guild doesn’t already exist. Use PlayerManager::get to only retrieve and not create.

Errors

Returns ClientError::NodesUnconfigured if no node has been configured via add.

Trait Implementations

impl Clone for Lavalink[src]

impl Debug for Lavalink[src]

Auto Trait Implementations

impl !RefUnwindSafe for Lavalink

impl Send for Lavalink

impl Sync for Lavalink

impl Unpin for Lavalink

impl !UnwindSafe for Lavalink

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

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

impl<T> Same<T> for T

type Output = T

Should always be Self

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

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,