API Reference#
NodePool#
- class lavapy.NodePool#
Lavapy NodePool class. This holds all the
Node
objects created withcreateNode()
.- classmethod balanced() lavapy.pool.Node #
An algorithm which selects the best Lavapy
Node
based on each node’s penalty.- Raises
NoNodesConnected – There are currently no nodes connected with the provided options.
InvalidNodeSearch – No nodes could be found with the current algorithm.
- Returns
A Lavapy node object.
- Return type
- classmethod closestNode(region: VoiceRegion)#
An algorithm which selects the best Lavapy
Node
based on how close it is to the desired target.- Raises
NoNodesConnected – There are currently no nodes connected with the provided options.
InvalidNodeSearch – No nodes could be found with the current algorithm.
- async classmethod createNode(*, client: Union[discord.Client, discord.AutoShardedClient, discord.ext.commands.Bot, discord.ext.commands.AutoShardedBot], host: str, port: int, password: str, region: Optional[VoiceRegion] = None, secure: bool = False, heartbeat: int = 60, resumeKey: Optional[str] = None, spotifyClient: Optional[SpotifyClient] = None, identifier: Optional[str] = None) Node #
This function is a coroutine.
Creates a Lavapy
Node
object and stores it for later use.- Parameters
client (Union[
discord.Client
,discord.AutoShardedClient
,discord.ext.commands.Bot
,discord.ext.commands.AutoShardedBot
]) – The client or bot object to assign to this node.host (str) – The IP address of the Lavalink server.
port (int) – The port of the Lavalink server.
password (str) – The password to the Lavalink server.
region (Optional[
discord.VoiceRegion
]) – The voice region to assign to this node.secure (bool) – Whether to connect securely to the Lavalink server or not.
heartbeat (int) – How many seconds to wait before sending a ping message and waiting for a response from the Lavalink server.
resumeKey (Optional[str]) – The resume key assigned to this node which allows a player to resume playing if it gets disconnected.
spotifyClient (Optional[SpotifyClient]) – A Lavapy Spotify client for interacting with Spotify.
identifier (Optional[str]) – The unique identifier for this node. If not supplied, it will be generated for you.
- Raises
NodeOccupied – A node with the given identifier already exists.
- Returns
A Lavapy node object.
- Return type
- classmethod extension(extension: Type[Playable])#
An algorithm which selects the best Lavapy
Node
based on the amount of players.- Raises
NoNodesConnected – There are currently no nodes connected with the provided options.
InvalidNodeSearch – No nodes could be found with the current algorithm.
- classmethod identifier(identifier: str)#
An algorithm which selects the best Lavapy
Node
based on its identifier.- Raises
NoNodesConnected – There are currently no nodes connected with the provided options.
InvalidNodeSearch – No nodes could be found with the current algorithm.
- classmethod minPlayers() lavapy.pool.Node #
An algorithm which selects the best Lavapy
Node
based on the amount of players.- Raises
NoNodesConnected – There are currently no nodes connected with the provided options.
InvalidNodeSearch – No nodes could be found with the current algorithm.
- Returns
A Lavapy node object.
- Return type
- classmethod nodes() Dict[str, lavapy.pool.Node] #
Returns a mapping of identifier to node objects.
Node#
Node#
- class lavapy.Node(client: Union[discord.Client, discord.AutoShardedClient, discord.ext.commands.Bot, discord.ext.commands.AutoShardedBot], host: str, port: int, password: str, region: Optional[discord.VoiceRegion], secure: bool, heartbeat: int, resumeKey: str, spotifyClient: Optional[SpotifyClient], identifier: str)#
Lavapy Node object.
Warning
This class should not be created manually. Please use
NodePool.createNode()
instead.- async buildTrack(cls: Type[Track], id: str) Track #
This function is a coroutine.
Builds a
Track
from a base64 track ID.- Parameters
- Raises
BuildTrackError – An error occurred while building the track.
- Returns
A Lavapy track object.
- Return type
- async connect() None #
This function is a coroutine.
Initialises the websocket connection to the Lavalink server.
- Raises
WebsocketAlreadyExists – The websocket for this node already exists.
- async disconnect(*, force: bool = False) None #
This function is a coroutine.
Disconnects this
Node
and removes it from theNodePool
.- Parameters
force (bool) – Whether to force the disconnection. This is currently not used.
- async getTracks(cls: Type[Playable], query: str) Optional[Union[Track, List[Track], MultiTrack]] #
This function is a coroutine.
Gets data about a
Track
orMultiTrack
from Lavalink.- Parameters
- Returns
A Lavapy resource which can be used to play music.
- Return type
Optional[Union[Track, List[Track], MultiTrack]]
- property client: Union[discord.Client, discord.AutoShardedClient, discord.ext.commands.Bot, discord.ext.commands.AutoShardedBot]#
Returns the client or bot object assigned to this node.
- property players: List[Player]#
Returns a list of all Lavapy player objects which are connected to this node.
- property region: Optional[discord.VoiceRegion]#
Returns the voice region assigned to this node.
- property session: aiohttp.client.ClientSession#
Returns the session used for sending and getting data.
- property spotifyClient: Optional[SpotifyClient]#
Returns the Spotify client associated with this node if there is one.
- property stats: Optional[lavapy.stats.Stats]#
Returns useful information sent by Lavalink about this node.
Stats#
Player#
Player#
- class lavapy.Player(client: Union[discord.Client, discord.AutoShardedClient, discord.ext.commands.Bot, discord.ext.commands.AutoShardedBot], channel: discord.VoiceChannel)#
Lavapy Player object. This subclasses
discord.VoiceProtocol
and such should be treated as one with additions.Examples
@commands.command() async def connect(self, channel: discord.VoiceChannel): voice_client = await channel.connect(cls=lavapy.Player)
Warning
This class should not be created manually but can be subclassed to add additional functionality. You should instead use
discord.VoiceChannel.connect()
and pass the player object to the cls kwarg.- Parameters
client (Union[
discord.Client
,discord.AutoShardedClient
,discord.ext.commands.Bot
,discord.ext.commands.AutoShardedBot
]) – A client or bot object.channel (discord.VoiceChannel) – A voice channel for the player to connect to.
- async addFilter(filter: LavapyFilter) None #
This function is a coroutine.
Adds a
LavapyFilter
to the player.Warning
This requires Lavalink 3.4 or greater..
- Parameters
filter (LavapyFilter) – The filter to apply to the player.
- Raises
FilterAlreadyExists – The specific filter is already applied.
- async connect(*, timeout: float, reconnect: bool, selfDeaf: bool = False, selfMute: bool = False) None #
This function is a coroutine.
Connects the player to a
discord.VoiceChannel
.
- async disconnect(*, force: bool = False) None #
This function is a coroutine.
Disconnects the player from a
discord.VoiceChannel
.- Parameters
force (bool) – Whether to force the disconnection. This is currently not used.
- async moveTo(channel: discord.channel.VoiceChannel) None #
This function is a coroutine.
Moves the player to another
discord.VoiceChannel
. If this is None, then the player will disconnect.- Parameters
channel (discord.VoiceChannel) – The voice channel to move to.
- async on_voice_server_update(data: Dict[str, str]) None #
This function is a coroutine.
Called when the client connects to a voice channel.
- async on_voice_state_update(data: Dict[str, Any]) None #
This function is a coroutine.
Called when the client’s voice state changes.
- Parameters
data (Dict[str, Any]) – The raw info sent by Discord about the client’s voice state.
- async play(track: Union[Track, PartialResource, MultiTrack], startTime: int = 0, endTime: int = 0, volume: float = 1, replace: bool = True, pause: bool = False) Optional[Track] #
This function is a coroutine.
Plays a given resource. If this resource is a
Track
, it is played normally. However, if it is aPartialResource
, then it is searched for and played (if the result of the search is a list of tracks, then the first is played). If the resource is aMultiTrack
then the first track is played and the rest and sent to theQueue
.- Parameters
track (Union[Track, PartialResource, MultiTrack]) – The Lavapy resource to play.
startTime (int) – The position in milliseconds to start at. By default, this is the beginning.
endTime (int) – The position in milliseconds to end at. By default, this is the end.
volume (int) – The volume at which the player should play the track at. This should be a value between 0 and 5 where 1 is 100%.
replace (bool) – A bool stating if the current track should be replaced or not.
pause (bool) – A bool stating if the track should start paused.
- Returns
The currently playing Lavapy track.
- Return type
Optional[Track]
- async removeFilter(filter: Union[LavapyFilter, Type[LavapyFilter]]) None #
This function is a coroutine.
Removes a
LavapyFilter
based on its name.Warning
This requires Lavalink 3.4 or greater.
- Parameters
filter (Union[LavapyFilter, Type[LavapyFilter]]) – The filter to remove. This can either be a non-initialised class like lavapy.Equalizer or an initialised one like lavapy.Equalizer.flat().
- Raises
FilterNotApplied – The specific filter is not applied.
- async resetFilter(filter: Type[LavapyFilter]) None #
This function is a coroutine.
Resets a
LavapyFilter
.Warning
This requires Lavalink 3.4 or greater.
- Parameters
filter (Type[LavapyFilter]) – The filter to reset. This should be a non-initialised class like lavapy.Equalizer or lavapy.Karaoke.
- Raises
FilterNotApplied – The specific filter is not applied.
- async seek(position: int) None #
This function is a coroutine.
Seek to a given position.
- Parameters
position (int) – The position to seek to.
- Raises
InvalidIdentifier – Seek position is bigger than the track length.
- async setVolume(volume: float) None #
This function is a coroutine.
Changes the
Player
’s volume.- Parameters
volume (float) – The new volume. This should be a value between 0 and 5 where 1 is 100%.
- startRepeat() None #
Repeats the currently playing track.
- Raises
RepeatException – The player is already repeating.
- stopRepeat() None #
Stops repeating the currently playing track.
- Raises
RepeatException – The player is not repeating.
- property filters: Dict[str, LavapyFilter]#
Returns all the currently applied filters if there are any.
- property guild: discord.guild.Guild#
Returns the guild this player is in.
- property isDead: bool#
Returns whether the player is dead or not. A player is considered dead if it has been destroyed and removed from stored players.
- property position: float#
Returns the current position of the track in seconds. If nothing is playing, this returns 0.
- property queue: lavapy.queue.Queue#
Returns a queue object which can be used to line up and retrieve tracks.
Queue#
- class lavapy.Queue(player: Player)#
A class representing a usable Queue.
- add(track: Track) None #
Adds a
Track
to the queue.- Parameters
track (Track) – The track to add to the queue.
- addIterable(iterable: Union[MultiTrack, Iterable[Track]]) None #
Adds an iterable to the
Queue
.- Parameters
iterable (Union[MultiTrack, Iterable[Track]]) – The iterable to add to the queue.
- next() Track #
Gets the next
Track
in the queue.- Raises
QueueEmpty – The current queue is empty.
RepeatException – Cannot get next track if player is repeating
- Returns
The next track in the queue.
- Return type
- previous() Track #
Gets the previous
Track
in the queue.- Raises
QueueEmpty – The current queue is empty.
RepeatException – Cannot get previous track if player is repeating
- Returns
The previous track in the queue.
- Return type
Playables#
Note
Remember to check if the specific source is enabled in your Lavalink application.yml.
DecodeQuery#
Playable#
- class lavapy.Playable(*data: Any)#
The base class for all Lavapy resources. This supports both query searches and identifier searches.
Warning
This class should not be created manually. Instead use a subclass of
Track
orMultiTrack
.- async classmethod search(query: str, node: Node = None, returnFirst: bool = True, partial: bool = False) Optional[Union[Playable, Track, List[Track], PartialResource, List[PartialResource], MultiTrack]] #
This function is a coroutine.
Performs a search to Lavalink for a specific resource.
- Parameters
query (str) – The query to search for.
node (Node) – The Lavapy Node to use for searching. If this is not supplied, a random one from the node pool will be retrieved.
returnFirst (bool) – Whether to return only the first result or not.
partial (bool) – Whether to return a Lavapy partial resource or not.
- Returns
A Lavapy resource or a list of resources which can be used to play music.
- Return type
Optional[Union[Playable, Track, List[Track], PartialResource, List[PartialResource], MultiTrack]]
PartialResource#
- class lavapy.PartialResource(cls: Type[lavapy.tracks.Playable], query: str)#
A class which searches for the given query at playtime.
Warning
It is advised not to create this manually, however, it is possible to do so.
- Parameters
cls (Type[Playable]) – The resource to create a instance of at playtime.
query (str) – The query to search for at playtime.
warning:: (..) – This object will only search for the given query at playtime. Full resource information will be missing until it has been searched. It is advised not to create this manually, however, it is possible to do so.
- property cls: Type[lavapy.tracks.Playable]#
Returns the resource which will be created at playtime.
Track#
MultiTrack#
- class lavapy.MultiTrack(name: str, tracks: List[lavapy.tracks.Track])#
The base class for all Lavapy MultiTrack resources. These could be playlists or albums.
Warning
It is advised not to create this manually, however, it is possible to do so.
- Parameters
- property tracks: List[lavapy.tracks.Track]#
Returns the playlist’s tracks.
YoutubeTrack#
- class lavapy.YoutubeTrack(id: str, info: Dict[str, Any])#
Bases:
lavapy.tracks.Track
,lavapy.tracks.Playable
A track created using a search to Youtube.
YoutubeMusicTrack#
- class lavapy.YoutubeMusicTrack(id: str, info: Dict[str, Any])#
Bases:
lavapy.tracks.Track
,lavapy.tracks.Playable
A track created using a search to Youtube Music.
SoundcloudTrack#
- class lavapy.SoundcloudTrack(id: str, info: Dict[str, Any])#
Bases:
lavapy.tracks.Track
,lavapy.tracks.Playable
A track created using a search to Soundcloud.
LocalTrack#
- class lavapy.LocalTrack(id: str, info: Dict[str, Any])#
Bases:
lavapy.tracks.Track
,lavapy.tracks.Playable
A track created using a search to a Discord mp3 file.
YoutubePlaylist#
- class lavapy.YoutubePlaylist(name: str, tracks: List[lavapy.tracks.Track])#
Bases:
lavapy.tracks.MultiTrack
,lavapy.tracks.Playable
A playlist created using a search to Youtube.
Filters#
LavapyFilter#
Equalizer#
- class lavapy.Equalizer(levels: List[Tuple[int, float]], name: str)#
Bases:
lavapy.filters.LavapyFilter
A class representing a usable equalizer.
- Parameters
- classmethod build(levels: List[Tuple[int, float]], name: str = 'CustomEqualizer') lavapy.filters.Equalizer #
Build a custom equalizer with the given levels.
- Parameters
levels (List[Tuple[int, float]]) – A custom list of tuple pairs containing a band int and gain float. You will have to construct this yourself. There should be between 0 and 14 bands with each gain being between -0.25 and 1
name (str) – An optional string to name this equalizer. If this is not supplied, it will be set to ‘CustomEqualizer’.
- Returns
A custom equalizer object.
- Return type
- classmethod flat() lavapy.filters.Equalizer #
A flat equalizer. This will not provide a cut or boost to any frequency.
- Returns
A flat equalizer object.
- Return type
Karaoke#
Timescale#
- class lavapy.Timescale(speed: float = 1.0, pitch: float = 1.0, rate: float = 1.0)#
Bases:
lavapy.filters.LavapyFilter
Changes the speed, pitch and rate of a track. You can make some very cool sound effects with this such as a vaporwave-esque filter which slows the track down a certain amount to produce said effect.
Tremolo#
- class lavapy.Tremolo(frequency: float = 2.0, depth: float = 0.5)#
Bases:
lavapy.filters.LavapyFilter
Uses amplification to create a shuddering effect, where the volume quickly oscillates.
Here is an Example.
- Raises
InvalidFilterArgument – An invalid filter argument has been passed.
Vibrato#
- class lavapy.Vibrato(frequency: float = 2.0, depth: float = 0.5)#
Bases:
lavapy.filters.LavapyFilter
Similar to
Tremolo
but oscillates the pitch instead of the volume.- Raises
InvalidFilterArgument – An invalid filter argument has been passed.
Rotation#
- class lavapy.Rotation(rotationHz: float = 0.0)#
Bases:
lavapy.filters.LavapyFilter
Rotates the sound around the stereo channels/user headphones aka Audio Panning.
Here is an Example ( without the reverb).
- Parameters
rotationHz (float) – The frequency of the audio rotating around the listener in hertz (0.2 is similar to the example above).
Distortion#
- class lavapy.Distortion(sinOffset: float = 0.0, sinScale: float = 1.0, cosOffset: float = 0.0, cosScale: float = 1.0, tanOffset: float = 0.0, tanScale: float = 1.0, offset: float = 0.0, scale: float = 1.0)#
Bases:
lavapy.filters.LavapyFilter
Distorts the sound. This can generate some pretty unique audio effects.
ChannelMix#
- class lavapy.ChannelMix(leftToLeft: float = 1.0, leftToRight: float = 0.0, rightToLeft: float = 0.0, rightToRight: float = 1.0)#
Bases:
lavapy.filters.LavapyFilter
Mixes both channels (left and right) with a configurable factor on how much each channel affects the other. By default, both channel are kept separate from each other. Setting all factors to 0.5 means both channels get the same audio.
LowPass#
- class lavapy.LowPass(smoothing: float = 20.0)#
Bases:
lavapy.filters.LavapyFilter
Suppresses higher frequencies, while allowing lower frequencies to pass through.
Events#
LavapyEvent#
- class lavapy.LavapyEvent(event: str, player: Optional[Player])#
Base Lavapy event. Every event inherits from this.
If you want to listen to these events, use a
discord.ext.commands.Bot.listen()
.
TrackStartEvent#
- class lavapy.TrackStartEvent(player: Player, track: Track)#
Bases:
lavapy.events.LavapyEvent
Fired when a
Track
starts playing. This can be listened to with:@bot.listen() async def on_lavapy_track_start(player, track): ...
TrackEndEvent#
TrackExceptionEvent#
TrackStuckEvent#
WebsocketOpenEvent#
- class lavapy.WebsocketOpenEvent(node: Node)#
Bases:
lavapy.events.LavapyEvent
Fired when a websocket connection to a
Node
is open. This can be listened to with:@bot.listen() async def on_lavapy_websocket_open(node): pass
- Parameters
node (lavapy.pool.Node) – A Lavapy node object.
WebsocketClosedEvent#
- class lavapy.WebsocketClosedEvent(node: Node, data: Dict[str, Any])#
Bases:
lavapy.events.LavapyEvent
Fired when a websocket connection to a
Node
is closed. This can be listened to with:@bot.listen() async def on_lavapy_websocket_closed(node, reason, code, byRemote): pass
- Parameters
node (lavapy.pool.Node) – A Lavapy node object.
data (Dict[str, Any]) – The raw event data.
Exceptions#
- exception lavapy.LavapyException#
Base Lavapy exception. Every exception inherits from this.
- exception lavapy.NoNodesConnected#
Bases:
lavapy.exceptions.LavapyException
Exception raised when an operation is attempted with nodes and there are none connected.
- exception lavapy.NodeOccupied#
Bases:
lavapy.exceptions.LavapyException
Exception raised when node identifiers conflict.
- exception lavapy.InvalidSeekPosition#
Bases:
lavapy.exceptions.LavapyException
Exception raised when an invalid seek position is passed.
- exception lavapy.QueueEmpty#
Bases:
lavapy.exceptions.LavapyException
Exception raised when attempting to get a track from an empty queue.
- exception lavapy.InvalidFilterArgument#
Bases:
lavapy.exceptions.LavapyException
Exception raised when an invalid argument is passed to a filter.
- exception lavapy.FilterAlreadyExists#
Bases:
lavapy.exceptions.LavapyException
Exception raised when a new filter is attempted to be applied, but it already exists.
- exception lavapy.FilterNotApplied#
Bases:
lavapy.exceptions.LavapyException
Exception raised when a filter is attempted to be removed, but it is not applied.
- exception lavapy.InvalidNodeSearch#
Bases:
lavapy.exceptions.LavapyException
Exception raised when a search for a node is invalid.
- exception lavapy.RepeatException#
Bases:
lavapy.exceptions.LavapyException
Exception raised when an error occurred when enabling or disabling repeat.
- exception lavapy.LavalinkException#
Bases:
lavapy.exceptions.LavapyException
Base exception raised when an error occurs communicating with Lavalink.
- exception lavapy.LoadTrackError#
Bases:
lavapy.exceptions.LavalinkException
Exception raised when an error occurred when loading a track.
- exception lavapy.BuildTrackError#
Bases:
lavapy.exceptions.LavalinkException
Exception raised when an error occurred when building a track.