pub struct LavalinkClient {
pub nodes: Vec<Arc<Node>>,
pub players: Arc<DashMap<GuildId, (ArcSwapOption<PlayerContext>, Arc<Node>)>>,
pub events: Events,
/* private fields */
}
Expand description
The main client, where everything gets done, from events to requests to management.
Fields§
§nodes: Vec<Arc<Node>>
§players: Arc<DashMap<GuildId, (ArcSwapOption<PlayerContext>, Arc<Node>)>>
§events: Events
Implementations§
Source§impl LavalinkClient
impl LavalinkClient
Sourcepub async fn new(
events: Events,
nodes: Vec<NodeBuilder>,
strategy: NodeDistributionStrategy,
) -> LavalinkClient
pub async fn new( events: Events, nodes: Vec<NodeBuilder>, strategy: NodeDistributionStrategy, ) -> LavalinkClient
Create a new Lavalink Client. It also establish the connection(s) and start listening for events.
§Parameters
events
: The lavalink event handler.nodes
: List of nodes to connect to.
Sourcepub async fn new_with_data<Data: Any + Send + Sync>(
events: Events,
nodes: Vec<NodeBuilder>,
strategy: NodeDistributionStrategy,
user_data: Arc<Data>,
) -> LavalinkClient
pub async fn new_with_data<Data: Any + Send + Sync>( events: Events, nodes: Vec<NodeBuilder>, strategy: NodeDistributionStrategy, user_data: Arc<Data>, ) -> LavalinkClient
Create a new Lavalink Client with custom user data. It also establish the connection(s) and start listening for events.
§Parameters
events
: The lavalink event handler.nodes
: List of nodes to connect to.user_data
: Set the data that will be accessible from anywhere with the client.
pub fn get_node_by_index(&self, idx: usize) -> Option<Arc<Node>>
Sourcepub async fn get_node_for_guild(
&self,
guild_id: impl Into<GuildId>,
) -> Arc<Node>
pub async fn get_node_for_guild( &self, guild_id: impl Into<GuildId>, ) -> Arc<Node>
Get the node assigned to a guild.
Sourcepub fn get_player_context(
&self,
guild_id: impl Into<GuildId>,
) -> Option<PlayerContext>
pub fn get_player_context( &self, guild_id: impl Into<GuildId>, ) -> Option<PlayerContext>
Get the player context for a guild, if it exists.
Sourcepub async fn create_player(
&self,
guild_id: impl Into<GuildId>,
connection_info: impl Into<ConnectionInfo>,
) -> LavalinkResult<Player>
pub async fn create_player( &self, guild_id: impl Into<GuildId>, connection_info: impl Into<ConnectionInfo>, ) -> LavalinkResult<Player>
Creates a new player without a context.
Calling this method is required to play tracks on a guild.
Sourcepub async fn create_player_context(
&self,
guild_id: impl Into<GuildId>,
connection_info: impl Into<ConnectionInfo>,
) -> LavalinkResult<PlayerContext>
pub async fn create_player_context( &self, guild_id: impl Into<GuildId>, connection_info: impl Into<ConnectionInfo>, ) -> LavalinkResult<PlayerContext>
Creates a new player with context.
Calling this method is required to create the initial player, and be able to use the built-in queue.
Sourcepub async fn create_player_context_with_data<Data: Any + Send + Sync>(
&self,
guild_id: impl Into<GuildId>,
connection_info: impl Into<ConnectionInfo>,
user_data: Arc<Data>,
) -> LavalinkResult<PlayerContext>
pub async fn create_player_context_with_data<Data: Any + Send + Sync>( &self, guild_id: impl Into<GuildId>, connection_info: impl Into<ConnectionInfo>, user_data: Arc<Data>, ) -> LavalinkResult<PlayerContext>
Creates a new player with context with custom user data.
Calling this method is required to create the initial player, and be able to use the built-in queue.
Sourcepub async fn delete_player(
&self,
guild_id: impl Into<GuildId>,
) -> LavalinkResult<()>
pub async fn delete_player( &self, guild_id: impl Into<GuildId>, ) -> LavalinkResult<()>
Deletes and closes a specific player context, if it exists.
Sourcepub async fn delete_all_player_contexts(&self) -> LavalinkResult<()>
pub async fn delete_all_player_contexts(&self) -> LavalinkResult<()>
Deletes all stored player contexts.
This is useful to put on the ready event, to close already open players in case the Lavalink server restarts.
Sourcepub async fn update_player(
&self,
guild_id: impl Into<GuildId>,
update_player: &UpdatePlayer,
no_replace: bool,
) -> LavalinkResult<Player>
pub async fn update_player( &self, guild_id: impl Into<GuildId>, update_player: &UpdatePlayer, no_replace: bool, ) -> LavalinkResult<Player>
Request a raw player update.
Sourcepub async fn load_tracks(
&self,
guild_id: impl Into<GuildId>,
identifier: &str,
) -> LavalinkResult<Track>
pub async fn load_tracks( &self, guild_id: impl Into<GuildId>, identifier: &str, ) -> LavalinkResult<Track>
Resolves audio tracks for use with the update_player
endpoint.
§Parameters
identifier
: A track identifier.- Can be a url: “https://youtu.be/watch?v=DrM2lo6B04I”
- A unique identifier: “DrM2lo6B04I”
- A search: “
Sourcepub async fn decode_track(
&self,
guild_id: impl Into<GuildId>,
track: &str,
) -> LavalinkResult<TrackData>
pub async fn decode_track( &self, guild_id: impl Into<GuildId>, track: &str, ) -> LavalinkResult<TrackData>
Sourcepub async fn decode_tracks(
&self,
guild_id: impl Into<GuildId>,
tracks: &[String],
) -> LavalinkResult<Vec<TrackData>>
pub async fn decode_tracks( &self, guild_id: impl Into<GuildId>, tracks: &[String], ) -> LavalinkResult<Vec<TrackData>>
Sourcepub async fn request_version(
&self,
guild_id: impl Into<GuildId>,
) -> LavalinkResult<String>
pub async fn request_version( &self, guild_id: impl Into<GuildId>, ) -> LavalinkResult<String>
Request Lavalink server version.
Sourcepub async fn request_stats(
&self,
guild_id: impl Into<GuildId>,
) -> LavalinkResult<Stats>
pub async fn request_stats( &self, guild_id: impl Into<GuildId>, ) -> LavalinkResult<Stats>
Request Lavalink statistics.
NOTE: The frame stats will never be returned.
Sourcepub async fn request_info(
&self,
guild_id: impl Into<GuildId>,
) -> LavalinkResult<Info>
pub async fn request_info( &self, guild_id: impl Into<GuildId>, ) -> LavalinkResult<Info>
Request Lavalink server information.
Sourcepub async fn request_player(
&self,
guild_id: impl Into<GuildId>,
) -> LavalinkResult<Player>
pub async fn request_player( &self, guild_id: impl Into<GuildId>, ) -> LavalinkResult<Player>
Returns the player for the guild.
Sourcepub async fn request_all_players(
&self,
guild_id: impl Into<GuildId>,
) -> LavalinkResult<Vec<Player>>
pub async fn request_all_players( &self, guild_id: impl Into<GuildId>, ) -> LavalinkResult<Vec<Player>>
Returns all players from the Node bound to the guild.
Sourcepub fn data<Data: Send + Sync + 'static>(&self) -> LavalinkResult<Arc<Data>>
pub fn data<Data: Send + Sync + 'static>(&self) -> LavalinkResult<Arc<Data>>
Get the custom data provided when creating the client.
§Errors
Returns LavalinkError::InvalidDataType
if the type argument provided does not match
the type of the data provided, or if no data was provided when creating the client.
Sourcepub fn handle_voice_server_update(
&self,
guild_id: impl Into<GuildId>,
token: String,
endpoint: Option<String>,
)
pub fn handle_voice_server_update( &self, guild_id: impl Into<GuildId>, token: String, endpoint: Option<String>, )
Method to handle the VOICE_SERVER_UPDATE event.
Sourcepub fn handle_voice_state_update(
&self,
guild_id: impl Into<GuildId>,
channel_id: Option<impl Into<ChannelId>>,
user_id: impl Into<UserId>,
session_id: String,
)
pub fn handle_voice_state_update( &self, guild_id: impl Into<GuildId>, channel_id: Option<impl Into<ChannelId>>, user_id: impl Into<UserId>, session_id: String, )
Method to handle the VOICE_STATE_UPDATE event.
Sourcepub async fn get_connection_info(
&self,
guild_id: impl Into<GuildId>,
timeout: Duration,
) -> LavalinkResult<ConnectionInfo>
pub async fn get_connection_info( &self, guild_id: impl Into<GuildId>, timeout: Duration, ) -> LavalinkResult<ConnectionInfo>
Returns the connection information needed for creating a player.
This methods requires that handle_voice_server_update
and handle_voice_state_update
be
defined and handled inside their respective discord events.
§Note
This methid may take longer to execute than the set timeout. Every event handled will reset the timeout. This method also uses interior mutability via logs, so if it is called multiple times with the same guild_id, it will execute them sequentially.
§Errors
If the custom timeout was reached. This can happen if the bot never connected to the voice channel, or the events were not handled correctly, or the timeout was too short.
Source§impl LavalinkClient
impl LavalinkClient
pub fn get_node_for_guild_py<'a>( &self, py: Python<'a>, guild_id: PyGuildId, ) -> PyResult<&'a PyAny>
Trait Implementations§
Source§impl Clone for LavalinkClient
impl Clone for LavalinkClient
Source§fn clone(&self) -> LavalinkClient
fn clone(&self) -> LavalinkClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl PyClass for LavalinkClient
impl PyClass for LavalinkClient
Source§impl PyClassImpl for LavalinkClient
impl PyClassImpl for LavalinkClient
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§type ThreadChecker = SendablePyClass<LavalinkClient>
type ThreadChecker = SendablePyClass<LavalinkClient>
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny
by default, and when you declare
#[pyclass(extends=PyDict)]
, it’s PyDict
.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
Source§impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a LavalinkClient
impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a LavalinkClient
Source§impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a mut LavalinkClient
impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a mut LavalinkClient
Source§impl PyMethods<LavalinkClient> for PyClassImplCollector<LavalinkClient>
impl PyMethods<LavalinkClient> for PyClassImplCollector<LavalinkClient>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for LavalinkClient
impl PyTypeInfo for LavalinkClient
Source§type AsRefTarget = PyCell<LavalinkClient>
type AsRefTarget = PyCell<LavalinkClient>
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
Source§fn type_object(py: Python<'_>) -> &PyType
fn type_object(py: Python<'_>) -> &PyType
Source§fn is_type_of(object: &PyAny) -> bool
fn is_type_of(object: &PyAny) -> bool
object
is an instance of this type or a subclass of this type.Source§fn is_exact_type_of(object: &PyAny) -> bool
fn is_exact_type_of(object: &PyAny) -> bool
object
is an instance of this type.