Event Reference#
WaveLink Events are events dispatched when certain events happen in Lavalink and Wavelink. All events must be coroutines.
Events are dispatched via discord.py and as such can be used with listener syntax.
For example:
An event listener in a cog…
@commands.Cog.listener()
async def on_wavelink_node_ready(node: Node):
print(f"Node {node.id} is ready!")
- wavelink.on_wavelink_node_ready(node: Node)#
Called when the Node you are connecting to has initialised and successfully connected to Lavalink.
- wavelink.on_wavelink_websocket_closed(player: Player, reason, code)#
Called when the Node websocket has been closed by Lavalink.
- wavelink.on_wavelink_track_end(player: player, track: Track, reason)#
Called when the current track has finished playing.
Abstract Base Classes#
- class wavelink.abc.Playable(id: str, info: Dict[str, Any])#
An ABC that defines the basic structure of a lavalink track resource.
- length#
The duration of the track.
- duration#
Alias to
length
.
- class wavelink.abc.Searchable#
NodePool#
- class wavelink.NodePool#
Wavelink NodePool class.
This class holds all the Node objects created with
create_node()
.- classmethod coroutine create_node(*, bot: discord.Client, host: str, port: int, password: str, https: bool = False, heartbeat: float = 30, region: Optional[discord.VoiceRegion] = None, spotify_client: Optional[spotify.SpotifyClient] = None, identifier: str = MISSING, dumps: Callable[[Any], str] = <function dumps>, resume_key: Optional[str] = None) Node #
This function is a coroutine.
Classmethod that creates a
Node
object and stores it for use with WaveLink.- Parameters
bot (Union[
discord.Client
]) – The discord.py Bot or Client class.host (
str
) – The lavalink host address.port (
int
) – The lavalink port.password (
str
) – The lavalink password for authentication.https (
bool
) – Connect to lavalink over https. Defaults to False.heartbeat (
float
) – The heartbeat in seconds for the node. Defaults to 30 seconds.region (Optional[
discord.VoiceRegion
]) – The discord.py VoiceRegion to assign to the node. This is useful for node region balancing.spotify_client (Optional[
wavelink.ext.spotify.SpotifyClient
]) – An optional SpotifyClient with credentials to use when searching for spotify tracks.identifier (
str
) – The unique identifier for this Node. By default this will be generated for you.
- Returns
The WaveLink Node object.
- Return type
- classmethod get_node(*, identifier: str = MISSING, region: discord.VoiceRegion = MISSING) Node #
Retrieve a Node from the NodePool.
- Parameters
identifier (
str
) – If provided this method will attempt to return the Node with the provided identifier.region (
discord.VoiceRegion
) – If provided this method will attempt to find the best Node with the provided region.
- Returns
The WaveLink Node object.
- Return type
- Raises
ZeroConnectedNodes – There are no currently connected Nodes on the pool with the provided options.
NoMatchingNode – No Node exists with the provided identifier.
Node#
- asyncbuild_track
- asyncdisconnect
- defget_player
- asyncget_playlist
- asyncget_tracks
- defis_connected
- class wavelink.Node(bot: discord.Client, host: str, port: int, password: str, https: bool, heartbeat: float, region: Optional[discord.VoiceRegion], spotify: Optional[spotify.SpotifyClient], identifier: str, dumps: Callable[[Any], str], resume_key: Optional[str])#
WaveLink Node object.
- bot#
The discord.py Bot object.
- Type
discord.Client
Warning
This class should not be created manually. Please use
NodePool.create_node()
instead.- coroutine build_track(cls: Type[PT], identifier: str) PT #
This function is a coroutine.
Build a track object with a valid track identifier.
- Parameters
cls (Type[
abc.Playable
]) – The type of which track should be returned, this must subclassabc.Playable
.identifier (str) – The tracks unique Base64 encoded identifier. This is usually retrieved from various lavalink events.
- Returns
The track built from a Base64 identifier.
- Return type
- Raises
BuildTrackError – Decoding and building the track failed.
- coroutine disconnect(*, force: bool = False) None #
Disconnect this Node and remove it from the NodePool.
This is a graceful shutdown of the node.
- get_player(guild: discord.Guild) Optional[Player] #
Returns a
Player
object playing in a specificdiscord.Guild
.- Parameters
guild (
discord.Guild
) – The Guild the player is in.- Returns
- Return type
Optional[
Player
]
- coroutine get_playlist(cls: Type[PLT], identifier: str) Optional[PLT] #
This function is a coroutine.
Search for and return a
abc.Playlist
given an identifier.- Parameters
cls (Type[
abc.Playlist
]) – The type of which playlist should be returned, this must subclassabc.Playlist
.identifier (str) – The playlist’s identifier. This may be a YouTube playlist URL for example.
- Returns
The related wavelink track object or
None
if none was found.- Return type
Optional[
abc.Playlist
]- Raises
LoadTrackError – Loading the playlist failed.
LavalinkException – An unspecified error occurred when loading the playlist.
- coroutine get_tracks(cls: Type[PT], query: str) List[PT] #
This function is a coroutine.
Search for and return a list of
abc.Playable
for a given query.- Parameters
cls (Type[
abc.Playable
]) – The type of which track should be returned, this must subclassabc.Playable
.query (str) – A query to use to search for tracks.
- Returns
A list of wavelink track objects.
- Return type
List[
abc.Playable
]- Raises
LoadTrackError – Loading the track failed.
LavalinkException – An unspecified error occurred when loading the track.
- property region: Optional[discord.VoiceRegion]#
The voice region of the Node.
Tracks#
Track#
SearchableTrack#
- class wavelink.SearchableTrack(id: str, info: dict)#
- classmethod coroutine convert(ctx: Context, argument: str) ST #
Converter which searches for and returns the first track.
Used as a type hint in a discord.py command.
- classmethod coroutine search(query: str, *, node: Node = MISSING, type: spotify.SpotifySearchType = None, return_first: Literal[False] = False) List[ST] #
- classmethod coroutine search(query: str, *, node: Node = MISSING, type: spotify.SpotifySearchType = None, return_first: Literal[True] = False) Optional[ST]
- classmethod coroutine search(query: str, *, node: Node = MISSING, return_first: Literal[False] = False) List[ST]
- classmethod coroutine search(query: str, *, node: Node = MISSING, return_first: Literal[True] = False) Optional[ST]
This function is a coroutine.
Search for tracks with the given query.
- Parameters
query (str) – The song to search for.
spotify_type (Optional[
spotify.SpotifySearchType
]) – An optional enum value to use when searching with Spotify.node (Optional[
wavelink.Node
]) – An optional Node to use to make the search with.return_first (Optional[bool]) – An optional bool which when set to True will return only the first track found. Defaults to False. Use this as True, when searching with LocalTrack.
- Returns
- Return type
YouTubeTrack#
YouTubeMusicTrack#
SoundCloudTrack#
YouTubePlaylist#
- class wavelink.YouTubePlaylist(data: dict)#
Represents a Lavalink YouTube playlist object.
- tracks#
The list of
YouTubeTrack
in the playlist.- Type
PartialTrack#
- class wavelink.PartialTrack(*, query: str, node: ~typing.Optional[~wavelink.pool.Node] = MISSING, cls: ~typing.Optional[~wavelink.tracks.SearchableTrack] = <class 'wavelink.tracks.YouTubeTrack'>)#
A PartialTrack object that searches for the given query at playtime.
- Parameters
query (str) – The query to search for at playtime.
node (Optional[
wavelink.Node
]) – An optional node to use when searching. Defaults to the best node.cls (Optional[
SearchableTrack
]) – An optional Non-Partial Track object to use when searching.
Warning
This object will only search for the given query at playtime. Full track information will be missing until it has been searched.
LocalTrack#
Player#
- asyncconnect
- asyncdisconnect
- defis_connected
- defis_paused
- defis_playing
- asyncmove_to
- asyncon_voice_server_update
- asyncon_voice_state_update
- asyncpause
- asyncplay
- asyncresume
- asyncseek
- asyncset_filter
- asyncset_pause
- asyncset_volume
- asyncstop
- class wavelink.Player(client: Client = MISSING, channel: Union[VoiceChannel, StageChannel] = MISSING, *, node: Node = MISSING)#
WaveLink Player object.
This class 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=wavelink.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.- coroutine connect(*, timeout: float, reconnect: bool, **kwargs: Any) None #
This function is a coroutine.
An abstract method called when the client initiates the connection request.
When a connection is requested initially, the library calls the constructor under
__init__
and then callsconnect()
. Ifconnect()
fails at some point thendisconnect()
is called.Within this method, to start the voice connection flow it is recommended to use
Guild.change_voice_state()
to start the flow. After which,on_voice_server_update()
andon_voice_state_update()
will be called. The order that these two are called is unspecified.
- coroutine disconnect(*, force: bool = False) None #
This function is a coroutine.
An abstract method called when the client terminates the connection.
See
cleanup()
.- Parameters
force (
bool
) – Whether the disconnection was forced.
- coroutine move_to(channel: VoiceChannel) None #
This function is a coroutine.
Moves the player to a different voice channel.
- Parameters
channel (
discord.VoiceChannel
) – The channel to move to. Must be a voice channel.
- coroutine on_voice_server_update(data: Dict[str, Any]) None #
This function is a coroutine.
An abstract method that is called when initially connecting to voice. This corresponds to
VOICE_SERVER_UPDATE
.- Parameters
data (
dict
) – The raw :ddocs:`voice server update payload <topics/gateway#voice-server-update>`.
- coroutine on_voice_state_update(data: Dict[str, Any]) None #
This function is a coroutine.
An abstract method that is called when the client’s voice state has changed. This corresponds to
VOICE_STATE_UPDATE
.- Parameters
data (
dict
) – The raw :ddocs:`voice state payload <resources/voice#voice-state-object>`.
- coroutine play(source: Playable, replace: bool = True, start: Optional[int] = None, end: Optional[int] = None, volume: Optional[int] = None, pause: Optional[bool] = None)#
This function is a coroutine.
Play a WaveLink Track.
- Parameters
source (
abc.Playable
) – Theabc.Playable
track to start playing.replace (bool) – Whether this track should replace the current track. Defaults to
True
.start (Optional[int]) – The position to start the track at in milliseconds. Defaults to
None
which will start the track at the beginning.end (Optional[int]) – The position to end the track at in milliseconds. Defaults to
None
which means it will play until the end.volume (Optional[int]) – Sets the volume of the player. Must be between
0
and1000
. Defaults toNone
which will not change the volume.pause (bool) – Changes the players pause state. Defaults to
None
which will not change the pause state.
- Returns
The track that is now playing.
- Return type
- coroutine seek(position: int = 0) None #
This function is a coroutine.
Seek to the given position in the song.
- Parameters
position (int) – The position as an int in milliseconds to seek to.
- coroutine set_filter(_filter: Filter, /, *, seek: bool = False) None #
This function is a coroutine.
Set the player’s filter.
- Parameters
filter (
wavelink.Filter
) – The filter to apply to the player.seek (bool) – Whether to seek the player to its current position which will apply the filter immediately. Defaults to
False
.
- coroutine set_pause(pause: bool) None #
This function is a coroutine.
Set the players paused state.
- Parameters
pause (bool) – A bool indicating if the player’s paused state should be set to True or False.
- coroutine set_volume(volume: int) None #
This function is a coroutine.
Sets the player’s volume. Accepts an int between
0
and1000
where100
means 100% volume.- Parameters
volume (int) – The volume to set the player to.
- property position: float#
The current seek position of the playing source in seconds. If nothing is playing this defaults to
0
.
- property user: ClientUser#
The
discord.ClientUser
of thediscord.Client
Queues#
- defclear
- defcopy
- defextend
- deffind_position
- defget
- defpop
- defput
- defput_at_front
- defput_at_index
- class wavelink.Queue(max_size: ~typing.Optional[int] = None, *, overflow: bool = True, queue_cls: ~typing.Type[~wavelink.queue.QT] = <class 'collections.deque'>)#
Basic Queue implementation for Playable objects.
Warning
This Queue class only accepts Playable objects. E.g YouTubeTrack, SoundCloudTrack.
- Parameters
max_size (Optional[int]) – The maximum allowed tracks in the Queue. If None, no maximum is used. Defaults to None.
- extend(iterable: Iterable[Playable], *, atomic: bool = True) None #
Add the members of the given iterable to the end of the queue.
If atomic is set to True, no tracks will be added upon any exceptions.
If atomic is set to False, as many tracks will be added as possible.
When overflow is enabled for the queue, atomic=True won’t prevent dropped items.
- find_position(item: Playable) int #
Find the position a given item within the queue.
Raises ValueError if item is not in queue.
- get() Playable #
Return next immediately available item in queue if any.
Raises QueueEmpty if no items in queue.
- pop() Playable #
Return item from the right end side of the queue.
Raises QueueEmpty if no items in queue.
- class wavelink.WaitQueue(max_size: Optional[int] = None, history_max_size: Optional[int] = None, history_cls=wavelink.queue.Queue[~QT])#
Queue for Playable objects designed for Players that allow waiting for new items with get_wait.
Note
WaitQueue is the default Player queue.
- coroutine get_wait() Playable #
This function is a coroutine.
Return the next item in queue once available.
Note
This will wait until an item is available to be retrieved.
Filters#
- class wavelink.Filter(_filter: Optional[Filter] = None, /, *, equalizer: Optional[Equalizer] = None, karaoke: Optional[Karaoke] = None, timescale: Optional[Timescale] = None, tremolo: Optional[Tremolo] = None, vibrato: Optional[Vibrato] = None, rotation: Optional[Rotation] = None, distortion: Optional[Distortion] = None, channel_mix: Optional[ChannelMix] = None, low_pass: Optional[LowPass] = None)#
A filter that can be applied to a track.
This filter accepts an instance of itself as a parameter which allows you to keep previous filters while also applying new ones or overwriting old ones.
- Parameters
filter (wavelink.Filter) – An instance of this filter class.
equalizer (wavelink.Equalizer) – An equalizer to apply to the track.
karaoke (wavelink.Karaoke) – A karaoke filter to apply to the track.
timescale (wavelink.Timescale) – A timescale filter to apply to the track.
tremolo (wavelink.Tremolo) – A tremolo filter to apply to the track.
vibrato (wavelink.Vibrato) – A vibrato filter to apply to the track.
rotation (wavelink.Rotation) – A rotation filter to apply to the track.
distortion (wavelink.Distortion) – A distortion filter to apply to the track.
channel_mix (wavelink.ChannelMix) – A channel mix filter to apply to the track.
low_pass (wavelink.LowPass) – A low pass filter to apply to the track.
- class wavelink.Equalizer(name: str = 'CustomEqualizer', *, bands: List[Tuple[int, float]])#
An equalizer filter.
- Parameters
- class wavelink.Karaoke(*, level: float = 1.0, mono_level: float = 1.0, filter_band: float = 220.0, filter_width: float = 100.0)#
A Karaoke filter.
The default values provided for all the parameters will play the track normally.
- class wavelink.Timescale(*, speed: float = 1.0, pitch: float = 1.0, rate: float = 1.0)#
A timescale filter.
Increases or decreases the speed, pitch, and/or rate of tracks.
The default values provided for
speed
,pitch
andrate
will play the track normally.
- class wavelink.Tremolo(*, frequency: float = 2.0, depth: float = 0.5)#
A tremolo filter.
Creates a shuddering effect by quickly changing the volume.
The default values provided for
frequency
anddepth
will play the track normally.
- class wavelink.Vibrato(*, frequency: float = 2.0, depth: float = 0.5)#
A vibrato filter.
Creates a vibrating effect by quickly changing the pitch.
The default values provided for
frequency
anddepth
will play the track normally.
- class wavelink.Rotation(speed: float = 5)#
A rotation filter.
Rotates the audio around stereo channels which can be used to create a 3D effect.
The default value provided for
speed
will play the track normally.- Parameters
speed (float) – The speed at which the audio should rotate.
- class wavelink.Distortion(*, sin_offset: float = 0.0, sin_scale: float = 1.0, cos_offset: float = 0.0, cos_scale: float = 1.0, tan_offset: float = 0.0, tan_scale: float = 1.0, offset: float = 0.0, scale: float = 1.0)#
A distortion filter.
- class wavelink.ChannelMix(*, left_to_left: float = 1.0, left_to_right: float = 0.0, right_to_left: float = 0.0, right_to_right: float = 1.0)#
A channel mix filter.
Allows you to control what channel audio from the track is actually played on.
Setting left_to_left and right_to_right to 1.0 will result in no change. Setting all channels to 0.5 will result in all channels receiving the same audio.
The default values provided for all the parameters will play the track normally.
- Parameters
left_to_left (float) – The “percentage” of audio from the left channel that should actually get played on the left channel.
left_to_right (float) – The “percentage” of audio from the left channel that should play on the right channel.
right_to_left (float) – The “percentage” of audio from the right channel that should actually get played on the right channel.
right_to_right (float) – The “percentage” of audio from the right channel that should play on the left channel.
- classmethod full_left() ChannelMix #
Returns a ChannelMix filter that will play the tracks left and right channels together only on the left channel.
- classmethod full_right() ChannelMix #
Returns a ChannelMix filter that will play the tracks left and right channels together only on the right channel.
- classmethod mono() ChannelMix #
Returns a ChannelMix filter that will play the track in mono.
- classmethod only_left() ChannelMix #
Returns a ChannelMix filter that will only play the tracks left channel.
- classmethod only_right() ChannelMix #
Returns a ChannelMix filter that will only play the tracks right channel.
- classmethod switch() ChannelMix #
Returns a ChannelMix filter that will switch the tracks left and right channels.
- class wavelink.LowPass(*, smoothing: float = 20)#
A low pass filter.
Suppresses higher frequencies while allowing lower frequencies to pass through.
The default value provided for
smoothing
will play the track normally.- Parameters
smoothing (float) – The factor by which the filter will block higher frequencies.
Exceptions#
- exception wavelink.WavelinkError#
- exception wavelink.AuthorizationFailure#
- exception wavelink.LavalinkException#
- exception wavelink.LoadTrackError#
- exception wavelink.BuildTrackError#
- exception wavelink.NodeOccupied#
- exception wavelink.InvalidIDProvided#
- exception wavelink.ZeroConnectedNodes#
- exception wavelink.NoMatchingNode#
- exception wavelink.QueueException#
- exception wavelink.QueueFull#
- exception wavelink.QueueEmpty#