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:

list[harmonize.connection.Node]

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:

harmonize.connection.Node

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]

classmethod close_all() None[source]#

Close all the nodes in the pool.

Return type:

None

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.

identifier#

A unique identifier for the node.

Type:

str

host#

The host address of the node.

Type:

str

port#

The port number of the node.

Type:

int

ssl#

A boolean indicating whether the node uses SSL.

Type:

bool

client#

The client instance associated with the node.

Type:

disnake.Client

cache_capacity#

The capacity of the node’s cache. Defaults to CacheCapacity.LITTLE.

Type:

harmonize.enums.CacheCapacity

retries#

The number of retries for the node’s transport. Defaults to 10.

Type:

int

heartbeat#

The heartbeat interval for the node’s transport. Defaults to 15.0.

Type:

float

status#

The current status of the node. Defaults to NodeStatus.DISCONNECTED

Type:

harmonize.enums.NodeStatus

stats#

Node statistics object associated with the node

Type:

harmonize.objects.Stats

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:
close() None[source]#

Closes the node’s transport connection.

Return type:

None

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:

bool

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:

dict[str, any]

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.

Parameters:

address (str) – The address to free.

Returns:

Whether the address was successfully freed.

Return type:

bool

Raises:
  • Forbidden – If the request is forbidden.

  • IOError – If the connection has been closed

async routeplanner_free_all_failing() bool[source]#

This function is a coroutine.

Frees all failing route planner addresses.

Returns:

Whether all addresses were successfully freed.

Return type:

bool

Raises:
  • Forbidden – If the request is forbidden.

  • IOError – If the connection has been closed

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:

harmonize.objects.LoadResult

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:

tracks (list[str]) – A list of track IDs to decode.

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:

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

dict[str, any]

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:

dict[str, any]

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:

list[dict[str, any]]

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:

Optional[dict[str, any]]

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:

Optional[dict[str, any]]

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 into

  • trace (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:

Union[T, str, bool, dict[any, any], list[any]]

Raises:
  • Forbidden – If the request is forbidden.

  • RequestError – Throws an error when the request fails.

  • IOError – If the connection has been closed