Connection#
- class harmonize.connection.Pool[source]#
- classmethod load_nodes(nodes: list[Node]) None[source]#
Loads multiple nodes into the pool.
- Parameters:
nodes (list[
harmonize.connection.Node]) β A list of nodes to load.- Return type:
None
- classmethod load_node(node: Node) None[source]#
Loads a single node into the pool.
- Parameters:
node (
harmonize.connection.Node) β The node to load into the pool.- Return type:
None
- classmethod get_nodes() list[Node][source]#
Retrieves a list of connected nodes from the pool.
- Return type:
- classmethod get_node(identifier: str) Node[source]#
Retrieves a node from the pool by its identifier.
- Parameters:
identifier (str) β The identifier of the node to retrieve.
- Return type:
- classmethod get_best_node() Node | None[source]#
Get the best node from the pool based on the number of players.
- Return type:
Optional[
harmonize.connection.Node]
- class harmonize.connection.Node(*, identifier: str, host: str, port: int, ssl: bool, password: str, client: Client, cache_capacity: CacheCapacity = CacheCapacity.LITTLE, retries: int = 10, heartbeat: float = 15.0)[source]#
Represents a lavalink node
Operations#
- x == y
Checks if two nodes are the same.
- x != y
Checks if two nodes are not the same.
- hash(x)
Return the nodeβs hash.
- client#
The client instance associated with the node.
- Type:
disnake.Client
- cache_capacity#
The capacity of the nodeβs cache. Defaults to CacheCapacity.LITTLE.
- status#
The current status of the node. Defaults to NodeStatus.DISCONNECTED
- stats#
Node statistics object associated with the node
- Type:
- connect(force: bool = False) None[source]#
Connects the nodeβs transport.
- Parameters:
force (bool) β Whether to force a reconnection. Defaults to False.
- Return type:
None
- Raises:
AuthorizationError β Throws when authorization fails
NodeUnknownError β Thrown at 404 status
- async destroy_player(guild_id: str | int) bool[source]#
This function is a coroutine.
Destroys a player with the given guild ID.
- Parameters:
guild_id (str | int) β The ID of the guild to destroy the player for.
- Returns:
Whether the player was successfully destroyed.
- Return type:
- Raises:
InvalidSession β Throws if player canβt be destroyed because of invalid session
Forbidden β If the request is forbidden.
RequestError β Throws an error when the request fails.
IOError β If the connection has been closed
- async get_routeplanner_status() dict[str, any][source]#
This function is a coroutine.
Retrieves the current status of the route planner.
- Returns:
The status of the route planner.
- Return type:
- Raises:
Forbidden β If the request is forbidden.
RequestError β Throws an error when the request fails.
IOError β If the connection has been closed
- async routeplanner_free_address(address: str) bool[source]#
This function is a coroutine.
Frees a route planner address.
- async routeplanner_free_all_failing() bool[source]#
This function is a coroutine.
Frees all failing route planner addresses.
- async get_tracks(query: str) LoadResult[source]#
This function is a coroutine.
Retrieves tracks based on the provided query.
- Parameters:
query (str) β The query string to search for tracks.
- Returns:
The result of the load tracks request.
- Return type:
- Raises:
Forbidden β If the request is forbidden.
RequestError β Throws an error when the request fails.
IOError β If the connection has been closed
- async decode_tracks(tracks: list[str]) list[Track][source]#
This function is a coroutine.
Decodes a list of tracks.
- Parameters:
- Returns:
A list of decoded Track objects.
- Return type:
list[
harmonize.objects.Track]- Raises:
Forbidden β If the request is forbidden.
RequestError β Throws an error when the request fails.
IOError β If the connection has been closed
- async decode_track(track: str) Track[source]#
This function is a coroutine.
Decodes a single track.
- Parameters:
track (str) β The track ID to decode.
- Returns:
The decoded Track object.
- Return type:
- Raises:
Forbidden β If the request is forbidden.
RequestError β Throws an error when the request fails.
IOError β If the connection has been closed
- async get_info() dict[str, any][source]#
This function is a coroutine.
Retrieves information about the node.
- Returns:
- dict[str, any]
A dictionary containing information about the node.
- Raises:
Forbidden β If the request is forbidden.
RequestError β Throws an error when the request fails.
IOError β If the connection has been closed
- async get_stats() dict[str, any][source]#
This function is a coroutine.
Retrieves statistics about the node.
- Returns:
A dictionary containing statistics about the node.
- Return type:
- Raises:
Forbidden β If the request is forbidden.
RequestError β Throws an error when the request fails.
IOError β If the connection has been closed
- async get_player(guild_id: str | int) dict[str, any][source]#
This function is a coroutine.
Retrieves a player with the given guild ID.
- Parameters:
guild_id (str | int) β The ID of the guild to retrieve the player for.
- Returns:
A dictionary containing information about the player.
- Return type:
- Raises:
InvalidSession β Throws if player canβt be retrieved because of invalid session.
Forbidden β If the request is forbidden.
RequestError β Throws an error when the request fails.
IOError β If the connection has been closed
- async get_players() list[dict[str, any]][source]#
This function is a coroutine.
Retrieves a list of players associated with the session ID.
- Returns:
A list of dictionaries containing information about the players.
- Return type:
- Raises:
InvalidSession β Throws if player canβt be retrieved because of invalid session.
Forbidden β If the request is forbidden.
RequestError β Throws an error when the request fails.
IOError β If the connection has been closed
- async update_player(guild_id: str | int, encoded_track: str | None = ..., identifier: str = ..., no_replace: bool = ..., position: int = ..., end_time: int = ..., volume: int = ..., paused: bool = ..., filters: list[Filter] | None = ..., voice_state: dict[str, any] = ..., user_data: dict[str, any] = ..., **kwargs) dict[str, any] | None[source]#
This function is a coroutine.
Updates the state of a player with the given guild ID.
- Parameters:
guild_id (Union[str, int]) β The ID of the guild to update the player for.
encoded_track (Optional[str] = MISSING) β The encoded track to update the player with. If both this and identifier are specified, an error will be raised.
identifier (str = MISSING) β The identifier of the track to update the player with. If both this and encoded_track are specified, an error will be raised.
no_replace (bool = MISSING) β Whether to replace the current track with the new one. Defaults to False.
position (int = MISSING) β The position of the track to update the player with. If not specified, the current position will be used.
end_time (int = MISSING) β The end time of the track to update the player with. If not specified, the current end time will be used.
volume (int = MISSING) β The volume of the track to update the player with. If not specified, the current volume will be used.
paused (bool = MISSING) β Whether the track is paused. If not specified, the current paused state will be used.
filters (Optional[list[Filter]] = MISSING) β A list of filters to apply to the track. If not specified, no filters will be applied.
voice_state (dict[str, any] = MISSING) β The voice state of the player. If not specified, the current voice state will be used.
user_data (dict[str, any] = MISSING) β Additional user data to associate with the player. If not specified, no additional user data will be associated.
**kwargs β Additional keyword arguments to pass to the request.
- Returns:
The updated player information, or None if no update was made.
- Return type:
- Raises:
InvalidSession β Throws if player canβt be retrieved because of invalid session.
ValueError β If both encoded_track and identifier are specified, or if the specified parameters are invalid.
Forbidden β If the request is forbidden.
RequestError β Throws an error when the request fails.
IOError β If the connection has been closed
- async update_session(session_id: int, resuming: bool = None, timeout: int = None) dict[str, any] | None[source]#
This function is a coroutine.
Updates the state of a session with the given session ID.
- Parameters:
session_id (int) β The ID of the session to update.
resuming (bool = None) β Whether the session should resume playback. Defaults to None.
timeout (int = None) β The timeout for the session, in seconds. Defaults to None.
- Returns:
The updated session information, or None if no update was made.
- Return type:
- Raises:
ValueError β If the specified parameters are invalid.
Forbidden β If the request is forbidden.
RequestError β Throws an error when the request fails.
IOError β If the connection has been closed
- async request(method: str, path: str, *, to: Serializable | None = None, trace: bool = False, **kwargs) T | str | bool | dict[any, any] | list[any][source]#
This function is a coroutine.
Sends an HTTP request to the specified path on the nodeβs transport.
- Parameters:
method (str) β The HTTP method to use for the request, e.g. βGETβ, βPOSTβ, βPUTβ, βDELETEβ.
path (str) β The path of the resource to request, relative to the base URL of the node.
to (
harmonize.abstract.Serializable= None) β The class of the object to deserialize the response intotrace (bool = False) β Whether to enable tracing for the request. Defaults to False.
**kwargs (dict) β Additional keyword arguments to pass to the request.
- Returns:
The response from the request, deserialized into the specified type or class if provided.
- Return type:
- Raises:
Forbidden β If the request is forbidden.
RequestError β Throws an error when the request fails.
IOError β If the connection has been closed