Struct LavalinkClient

Source
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

Source

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

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

pub fn get_node_by_index(&self, idx: usize) -> Option<Arc<Node>>

Source

pub async fn get_node_for_guild( &self, guild_id: impl Into<GuildId>, ) -> Arc<Node>

Get the node assigned to a guild.

Source

pub fn get_player_context( &self, guild_id: impl Into<GuildId>, ) -> Option<PlayerContext>

Get the player context for a guild, if it exists.

Source

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.

Source

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.

Source

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.

Source

pub async fn delete_player( &self, guild_id: impl Into<GuildId>, ) -> LavalinkResult<()>

Deletes and closes a specific player context, if it exists.

Source

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.

Source

pub async fn update_player( &self, guild_id: impl Into<GuildId>, update_player: &UpdatePlayer, no_replace: bool, ) -> LavalinkResult<Player>

Request a raw player update.

Source

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: “
Source

pub async fn decode_track( &self, guild_id: impl Into<GuildId>, track: &str, ) -> LavalinkResult<TrackData>

Decode a single track into its info.

§Parameters
  • track: base64 encoded track data.
Source

pub async fn decode_tracks( &self, guild_id: impl Into<GuildId>, tracks: &[String], ) -> LavalinkResult<Vec<TrackData>>

Decode multiple tracks into their info.

§Parameters
  • tracks: base64 encoded tracks.
Source

pub async fn request_version( &self, guild_id: impl Into<GuildId>, ) -> LavalinkResult<String>

Request Lavalink server version.

Source

pub async fn request_stats( &self, guild_id: impl Into<GuildId>, ) -> LavalinkResult<Stats>

Request Lavalink statistics.

NOTE: The frame stats will never be returned.

Source

pub async fn request_info( &self, guild_id: impl Into<GuildId>, ) -> LavalinkResult<Info>

Request Lavalink server information.

Source

pub async fn request_player( &self, guild_id: impl Into<GuildId>, ) -> LavalinkResult<Player>

Returns the player for the guild.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

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

Source§

fn clone(&self) -> LavalinkClient

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl IntoPy<Py<PyAny>> for LavalinkClient

Source§

fn into_py(self, py: Python<'_>) -> PyObject

Performs the conversion.
Source§

impl PyClass for LavalinkClient

Source§

type Frozen = False

Whether the pyclass is frozen. Read more
Source§

impl PyClassImpl for LavalinkClient

Source§

const IS_BASETYPE: bool = false

#[pyclass(subclass)]
Source§

const IS_SUBCLASS: bool = false

#[pyclass(extends=…)]
Source§

const IS_MAPPING: bool = false

#[pyclass(mapping)]
Source§

const IS_SEQUENCE: bool = false

#[pyclass(sequence)]
Source§

type BaseType = PyAny

Base class
Source§

type ThreadChecker = SendablePyClass<LavalinkClient>

This handles following two situations: Read more
Source§

type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild

Immutable or mutable
Source§

type Dict = PyClassDummySlot

Specify this class has #[pyclass(dict)] or not.
Source§

type WeakRef = PyClassDummySlot

Specify this class has #[pyclass(weakref)] or not.
Source§

type BaseNativeType = PyAny

The closest native ancestor. This is PyAny by default, and when you declare #[pyclass(extends=PyDict)], it’s PyDict.
Source§

fn items_iter() -> PyClassItemsIter

Source§

fn doc(py: Python<'_>) -> PyResult<&'static CStr>

Rendered class doc
Source§

fn lazy_type_object() -> &'static LazyTypeObject<Self>

Source§

fn dict_offset() -> Option<isize>

Source§

fn weaklist_offset() -> Option<isize>

Source§

impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a LavalinkClient

Source§

type Holder = Option<PyRef<'py, LavalinkClient>>

Source§

fn extract(obj: &'py PyAny, holder: &'a mut Self::Holder) -> PyResult<Self>

Source§

impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a mut LavalinkClient

Source§

type Holder = Option<PyRefMut<'py, LavalinkClient>>

Source§

fn extract(obj: &'py PyAny, holder: &'a mut Self::Holder) -> PyResult<Self>

Source§

impl PyMethods<LavalinkClient> for PyClassImplCollector<LavalinkClient>

Source§

fn py_methods(self) -> &'static PyClassItems

Source§

impl PyTypeInfo for LavalinkClient

Source§

const NAME: &'static str = "LavalinkClient"

Class name.
Source§

const MODULE: Option<&'static str> = ::core::option::Option::None

Module name, if any.
Source§

type AsRefTarget = PyCell<LavalinkClient>

Utility type to make Py::as_ref work.
Source§

fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject

Returns the PyTypeObject instance for this type.
Source§

fn type_object(py: Python<'_>) -> &PyType

Returns the safe abstraction over the type object.
Source§

fn is_type_of(object: &PyAny) -> bool

Checks if object is an instance of this type or a subclass of this type.
Source§

fn is_exact_type_of(object: &PyAny) -> bool

Checks if object is an instance of this type.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<'a, T> FromPyObject<'a> for T
where T: PyClass + Clone,

Source§

fn extract(obj: &'a PyAny) -> Result<T, PyErr>

Extracts Self from the source PyObject.
Source§

impl<T> Instrument for T

Source§

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

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

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> PyErrArguments for T
where T: IntoPy<Py<PyAny>> + Send + Sync,

Source§

fn arguments(self, py: Python<'_>) -> Py<PyAny>

Arguments for exception
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T

Source§

impl<T> Ungil for T
where T: Send,