pub struct Lavalink { /* private fields */ }
Expand description

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.

To use a Lavalink client instance in multiple tasks, consider wrapping it in an std::sync::Arc or std::rc::Rc.

Implementations§

source

pub fn new(user_id: Id<UserMarker>, shard_count: u32) -> Self

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.

source

pub fn new_with_resume( user_id: Id<UserMarker>, shard_count: u32, resume: impl Into<Option<Resume>> ) -> Self

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.

source

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

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 a ClientErrorType::NodesUnconfigured error type if no nodes have been added to the client when attempting to retrieve a guild’s player.

source

pub async fn add( &self, address: SocketAddr, authorization: impl Into<String> ) -> Result<(Arc<Node>, IncomingEvents), NodeError>

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.

§Errors

See the errors section of Node::connect.

source

pub fn remove(&self, address: SocketAddr) -> Option<(SocketAddr, Arc<Node>)>

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

This does not disconnect the node. Use Lavalink::disconnect instead. or drop all Nodes.

The node is returned if it existed.

source

pub fn disconnect(&self, address: SocketAddr) -> bool

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

Use Lavalink::remove if detaching a node from a Lavalink instance is required without closing the underlying connection.

Returns whether the node has been removed and disconnected.

source

pub async fn best(&self) -> Result<Arc<Node>, ClientError>

Determine the “best” node for new players according to available nodes’ penalty scores. Disconnected nodes will not be considered.

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

§Errors

Returns a ClientErrorType::NodesUnconfigured error type if there are no connected nodes available in the client.

source

pub const fn players(&self) -> &PlayerManager

Retrieve an immutable reference to the player manager.

source

pub async fn player( &self, guild_id: Id<GuildMarker> ) -> Result<Arc<Player>, ClientError>

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 a ClientError with a ClientErrorType::NodesUnconfigured type if no node has been configured via add.

Trait Implementations§

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more