[−][src]Struct twilight_lavalink::client::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]
user_id: UserId,
shard_count: u64,
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.
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]
&self,
address: SocketAddr,
authorization: impl Into<String>
) -> Result<(Node, UnboundedReceiver<IncomingEvent>), 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.
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]
&self,
guild_id: GuildId
) -> Result<Ref<'_, GuildId, 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 ClientError::NodesUnconfigured
if no node has been
configured via add
.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Lavalink
[src]
impl Send for Lavalink
[src]
impl Sync for Lavalink
[src]
impl Unpin for Lavalink
[src]
impl !UnwindSafe for Lavalink
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,