Events
You can listen to various events such as when a track starts, when the player is paused, etc., and respond to them with custom code.
1const voice = new Manager(client, { /* ••• */ });2
3voice.<eventName>({4 channel: '$channelId',5 code: `$songInfo[title]`6});
Available Events
Events are used to listen to specific changes of something, such as
members or channels, which you then can use for your commands.
This section will list all events.
- trackStart: Triggered when a track begins playing on the Lavalink node. This marks the start of the track’s playback.
- trackEnd: Occurs when a track finishes playing. This can happen when the track ends naturally or when it is stopped before completion.
- trackStuck: Triggered when a track gets stuck due to an error or issue like buffering or network problems, preventing it from progressing.
- trackPaused: Occurs when the playback of the track is paused, either manually or automatically due to external reasons (e.g., user interaction or system settings).
- trackResumed: Triggered when a previously paused track starts playing again, either after manual resumption or an automatic action.
- queueStart: Occurs when a new queue of tracks starts to be processed and played by the Lavalink node. This is the beginning of playback for a set of tracks.
- queueEnd: Triggered when the track queue finishes playing all the tracks. This event marks the end of the queue’s playback.
- nodeConnect: Triggered when a successful connection is established with a Lavalink node. The player can now interact with the node for streaming and playback.
- nodeReconnect: Occurs when a previously disconnected Lavalink node is reconnected. This could happen automatically after a temporary loss of connection.
- nodeDisconnect: This event occurs when the Lavalink node disconnects, either intentionally or due to a failure or disconnection.
- nodeError: Triggered when an error occurs with the Lavalink node, such as a failure in audio processing, network issues, or other internal node errors.
- nodeDestroy: Occurs when a Lavalink node is destroyed or cleaned up. This usually happens when the node is no longer needed or is being replaced.
- nodeDebug: This event provides debugging information about the Lavalink node. It’s often used to log detailed information about the node’s state for troubleshooting.
- socketClosed: Triggered when the socket connection between the client and Lavalink node is closed, either due to an error, timeout, or manual disconnection.
- playerCreate: Occurs when a new player instance is created. This happens when a new user starts playing music or a new player session is initialized.
- playerDestroy: Triggered when a player instance is destroyed. This occurs when a player session ends or is no longer needed.
- playerException: Occurs when an error or exception happens within the player, such as invalid operations, failed track loading, or playback errors.
- playerUpdate: Triggered when there’s an update to the player’s state, such as changes to the volume, track, or other settings that affect playback.
- playerMove: Triggered when the player moves to a different voice channel. This happens when the player switches its active voice connection, typically in response to a user command or action.
Handlers
1const voice = new Manager(client, { /* ••• */ });2
3// Load custom music event handlers from a directory. 'false' disables debug logs.4voice.loadVoiceEvents('./voice/', false);
Example Event File (in
/voice/trackStart.js
):
1module.exports = [{2 channel: '$channelId',3 type: 'trackStart',4 code: `$songInfo[title]`5}];