Events
Both the PlayerManager and each Player provide a few events you can listen to. If listening for those events on the PlayerManager
, all events will get the guild id as their first argument. The available events are:
ts
export interface PlayerEvents {
/** Emitted after a new track has started. */
trackStart: (track: Track) => void;
/**
* Emitted after a track has ended and before a new track has started.
* Will not be emitted when player is stopped while playing (`destroyed` event).
*/
trackEnd: (track: Track) => void;
/**
* Emitted after the player was stopped/destroyed/player left voice channel.
*/
destroyed: () => void;
/** Emitted before a player error is thrown. */
error: (error: PlayerError) => void;
}
Example
ts
import { PlayerManager } from "discord-player-plus";
const playerManager = new PlayerManager();
// listen for all guilds
playerManager.on("trackStart", (guildId, track) => {
console.log(`Started track ${track.title} in guild ${guildId}`);
});
// listen for individual guild/player
const player = playerManager.get("MY_GUILD_ID");
player.on("trackStart", (track) => {
console.log(`Started track ${track.title}`);
});
INFO
If you only want to listen to an event once use .once()
instead of .on()
.