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

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.

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.

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.

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.

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.

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.

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.

Retrieve an immutable reference to the player manager.

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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

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