Use the Events class¶
Lyra has different events that are triggered depending on events emitted by Lavalink or the library itself.
Here is the full list of events:
TrackStartEvent→on_lyra_track_startTrackEndEvent→on_lyra_track_endTrackStuckEvent→on_lyra_track_stuckTrackExceptionEvent→on_lyra_track_exceptionWebsocketClosedEvent→on_lyra_websocket_closedWebsocketOpenEvent→on_lyra_websocket_openLyricsFoundEvent→on_lyra_lyrics_foundLyricsUnavailableEvent→on_lyra_lyrics_unavailableLyricsUpdateEvent→on_lyra_lyrics_updateNodeConnectedEvent→on_lyra_node_connectedNodeDisconnectedEvent→on_lyra_node_disconnectedNodeReconnectingEvent→on_lyra_node_reconnectingPlayerCreatedEvent→on_lyra_player_createdVolumeChangedEvent→on_lyra_volume_changedPlayerConnectedEvent→on_lyra_player_connectedFiltersChangedEvent→on_lyra_filters_changed
Here is an example of how you would listen for the TrackStartEvent within a cog:
@commands.Cog.listener()
async def on_lyra_track_start(self, player: lava_lyra.Player, track: lava_lyra.Track):
print(f"Now playing: {track.title}")
Event definitions¶
Track events¶
All track-related events carry a Player object and a Track object.
on_lyra_track_start(player, track)— Fired when a track starts playing.on_lyra_track_end(player, track, reason)— Fired when a track ends.reasonis a string describing why the track ended.on_lyra_track_stuck(player, track, threshold)— Fired when a track gets stuck.thresholdis the time in milliseconds Lavalink waited before giving up.on_lyra_track_exception(player, track, error)— Fired when a track fails to play.erroris a string in the formatREASON: [SEVERITY].
Websocket events¶
on_lyra_websocket_closed(payload)— Fired when the websocket connection is closed.payloadcontains theGuild, close code, reason, and whether the close was remote.on_lyra_websocket_open(target, ssrc)— Fired when the websocket connection is opened.targetis the node’s IP andssrcis the 32-bit integer identifying the RTP stream.
Lyrics events¶
on_lyra_lyrics_found(player, track, lyrics)— Fired when lyrics are found for the current track.lyricsis aLyricsobject.on_lyra_lyrics_unavailable(player, track)— Fired when lyrics are not available for the current track.on_lyra_lyrics_update(player, track, line)— Fired when the current lyric line changes (live lyrics subscription).lineis aLyricLineobject.
Node events¶
on_lyra_node_connected(node_id, is_nodelink, reconnect)— Fired when a node connects.reconnectisTrueif this is a reconnection.on_lyra_node_disconnected(node_id, is_nodelink, player_count)— Fired when a node disconnects.on_lyra_node_reconnecting(node_id, is_nodelink, retry_in)— Fired when Lyra is attempting to reconnect to a node.retry_inis the delay in seconds.
Player state events¶
on_lyra_player_created(player, guild_id)— Fired when a player is created for a guild.on_lyra_volume_changed(player, volume)— Fired when the player volume changes.on_lyra_player_connected(player, voice)— Fired when the player connects to a voice channel.on_lyra_filters_changed(player, filters)— Fired when the player’s audio filters change.