Skip to main content
Version: v2.10.2 (current)

Player

Table of Contentsโ€‹

Class Definitionโ€‹

export class Player {}

Propertiesโ€‹

Property Type Description
autoplayTriesnumberThe number of autoplay attempts before emitting queueEnd.
bandsnumber[]The 15-band equalizer values. Defaults to 0.0 for each band.
clusterIdnumberThe cluster ID this player belongs to.
dynamicRepeatbooleanWhether dynamic repeat (shuffle-on-loop) is enabled.
dynamicRepeatIntervalMsnumber | nullThe interval in milliseconds for dynamic repeat. null if disabled.
filtersFiltersThe audio filters applied to this player.
guildIdstringThe guild ID this player belongs to.
isAutoplaybooleanWhether autoplay is enabled.
managerManagerThe Manager instance.
nodeNodeThe Node this player is connected to.
nowPlayingMessageAnyMessage | undefinedThe now playing message, if set.
optionsPlayerOptionsThe resolved options for this player.
pausedbooleanWhether the player is currently paused.
playingbooleanWhether the player is currently playing.
positionnumberThe current playback position in milliseconds.
queueIQueueThe queue for this player.
queueRepeatbooleanWhether queue repeat is enabled.
stateStateTypesThe current connection state of the player.
textChannelIdstring | nullThe text channel ID this player is bound to.
trackRepeatbooleanWhether track repeat is enabled.
voiceChannelIdstring | nullThe voice channel ID this player is connected to.
voiceStatePlayerVoiceStateThe current voice state for this player.
volumenumberThe current volume level. Range: 0โ€“1000 (or 0โ€“500 in filter mode).

Constructorโ€‹

new Player(options: PlayerOptions)
Parameter Type Description Optional
optionsPlayerOptionsThe player options.

Methodsโ€‹

autoMoveNode()โ€‹

async autoMoveNode(): Promise<Player | void>

Moves the player to the most suitable available node as determined by useableNode.

Returnsโ€‹

Type Description
Promise<Player | void>The player after being moved, or void.

connect()โ€‹

connect(): void

Connects the player to the configured voice channel. Throws if no voiceChannelId has been set.


deleteSponsorBlock()โ€‹

warning

Requires the SponsorBlock plugin on the player's node.

async deleteSponsorBlock(): Promise<void>

Removes all active SponsorBlock segment categories for this player.


destroy()โ€‹

async destroy(disconnect?: boolean): Promise<boolean>

Destroys the player, clears the queue, and removes it from the manager. Optionally disconnects from the voice channel first.

Parametersโ€‹

Parameter Type Description Optional
disconnectbooleanWhether to disconnect from the voice channel first. Defaults to true.

Returnsโ€‹

Type Description
Promise<boolean>true if the player was successfully removed from the manager.

disconnect()โ€‹

async disconnect(): Promise<this>

Disconnects the player from the voice channel, optionally pausing playback if pauseOnDisconnect is enabled.

Returnsโ€‹

Type Description
Promise<this>The player instance.

get()โ€‹

get<T>(key: string): T

Retrieves a custom data value by key.

Parametersโ€‹

Parameter Type Description Optional
keystringThe key to retrieve.

Returnsโ€‹

Type Description
TThe value cast to the specified type, or undefined.

getCurrentLyrics()โ€‹

warning

Requires the LavaLyrics plugin on the player's node.

async getCurrentLyrics(skipTrackSource?: boolean): Promise<Lyrics>

Fetches lyrics for the currently playing track. Returns an empty lyrics object if none are found.

Parametersโ€‹

Parameter Type Description Optional
skipTrackSourcebooleanWhether to skip the track's source URL. Defaults to false.

Returnsโ€‹

Type Description
Promise<Lyrics>The lyrics, or an empty lyrics object.

getData()โ€‹

getData(): Record<string, unknown>

Returns the full internal data store for this player.

Returnsโ€‹

Type Description
Record<string, unknown>The raw data object.

getDynamicLoopIntervalPublic()โ€‹

getDynamicLoopIntervalPublic(): NodeJS.Timeout | null

Returns the active dynamic repeat interval handle, or null if dynamic repeat is not enabled.

Returnsโ€‹

Type Description
NodeJS.Timeout | nullThe interval handle, or null.

getRecommendedTracks()โ€‹

async getRecommendedTracks(track: Track): Promise<Track[]>

Returns a list of recommended tracks based on the given track.

Parametersโ€‹

Parameter Type Description Optional
trackTrackThe track to base recommendations on.

Returnsโ€‹

Type Description
Promise<Track[]>The recommended tracks.

getSerializableData()โ€‹

getSerializableData(): Record<string, unknown>

Returns a shallow copy of the internal data store, safe for serialization.

Returnsโ€‹

Type Description
Record<string, unknown>A copy of the player's internal data.

getSponsorBlock()โ€‹

warning

Requires the SponsorBlock plugin on the player's node.

async getSponsorBlock(): Promise<SponsorBlockSegment[]>

Returns the active SponsorBlock segment categories for this player.

Returnsโ€‹

Type Description
Promise<SponsorBlockSegment[]>The active segment categories.

init()โ€‹

static init(manager: Manager): void

Initializes the static Manager reference used by all Player instances. Called internally by the manager.

Parametersโ€‹

Parameter Type Description Optional
managerManagerThe manager instance.

moveNode()โ€‹

async moveNode(identifier: string): Promise<Player>

Migrates the player to a different node, transferring voice state, position, volume, and filters.

Parametersโ€‹

Parameter Type Description Optional
identifierstringThe identifier of the target node.

Returnsโ€‹

Type Description
Promise<Player>The player after being moved.

pause()โ€‹

async pause(pause: boolean): Promise<this>

Pauses or resumes the player.

Parametersโ€‹

Parameter Type Description Optional
pausebooleantrue to pause, false to resume.

Returnsโ€‹

Type Description
Promise<this>The player instance.

play()โ€‹

async play(): Promise<Player>
async play(track: Track): Promise<Player>
async play(options: PlayOptions): Promise<Player>
async play(track: Track, options: PlayOptions): Promise<Player>

Starts playback. If a track is provided it becomes the current track. If only options are provided they apply to the current queue track.

Parametersโ€‹

Parameter Type Description Optional
trackTrackThe track to play.
optionsPlayOptionsPlayback options (start time, end time, etc.)

Returnsโ€‹

Type Description
Promise<Player>The player instance.

previous()โ€‹

async previous(addBackToQueue?: boolean): Promise<this>

Plays the most recent track from the previous queue. Optionally re-inserts the current track at the front of the queue.

Parametersโ€‹

Parameter Type Description Optional
addBackToQueuebooleanWhether to re-add the current track to the front of the queue. Defaults to true.

Returnsโ€‹

Type Description
Promise<this>The player instance.

removeVoiceReceiver()โ€‹

warning

Only available when the player is connected to a NodeLink node.

async removeVoiceReceiver(): Promise<void>

Closes and removes the voice receiver WebSocket connection for this player.


restart()โ€‹

async restart(): Promise<Player>

Restarts the currently playing track from position 0. If no track is current but the queue has tracks, plays the next one.

Returnsโ€‹

Type Description
Promise<Player>The player instance.

async search<T = unknown>(query: string | SearchQuery, requester?: T): Promise<SearchResult>

Shortcut for Manager#search(). Searches for tracks using the manager.

Parametersโ€‹

Parameter Type Description Optional
querystring | SearchQueryThe search query or URL.
requesterTThe user who requested the search.

Returnsโ€‹

Type Description
Promise<SearchResult>The search result.

seek()โ€‹

async seek(position: number): Promise<this>

Seeks to the specified position in the current track. The position is clamped to the valid range [0, duration].

Parametersโ€‹

Parameter Type Description Optional
positionnumberThe position in milliseconds to seek to.

Returnsโ€‹

Type Description
Promise<this>The player instance.

set()โ€‹

set(key: string, value: unknown): void

Stores a custom value on the player by key. Retrievable with get().

Parametersโ€‹

Parameter Type Description Optional
keystringThe key to store the value under.
valueunknownThe value to store.

setAutoplay()โ€‹

setAutoplay<T = unknown>(autoplayState: boolean, AutoplayUser?: T, tries?: number): this

Enables or disables autoplay. When enabled, the player will attempt to find and queue a recommended track when the queue ends.

Parametersโ€‹

Parameter Type Description Optional
autoplayStatebooleanWhether to enable autoplay.
AutoplayUserTThe bot user object used as the requester for autoplay tracks. Required if enabling.
triesnumberMax recommendation attempts before giving up. Defaults to 3.

Returnsโ€‹

Type Description
thisThe player instance.

setDynamicRepeat()โ€‹

async setDynamicRepeat(repeat: boolean, ms: number): Promise<this>

Enables or disables dynamic repeat, which shuffles and re-queues tracks on an interval.

Parametersโ€‹

Parameter Type Description Optional
repeatbooleanWhether to enable dynamic repeat.
msnumberThe shuffle interval in milliseconds. Ignored when disabling.

Returnsโ€‹

Type Description
Promise<this>The player instance.

setNowPlayingMessage()โ€‹

setNowPlayingMessage(message: AnyMessage): AnyMessage

Sets the now playing message on the player. Also stored internally via set().

Parametersโ€‹

Parameter Type Description Optional
messageAnyMessageThe message to set.

Returnsโ€‹

Type Description
AnyMessageThe now playing message.

setQueueRepeat()โ€‹

setQueueRepeat(repeat: boolean): this

Enables or disables queue repeat. Disables trackRepeat and dynamicRepeat if currently active.

Parametersโ€‹

Parameter Type Description Optional
repeatbooleanWhether to enable queue repeat.

Returnsโ€‹

Type Description
thisThe player instance.

setSponsorBlock()โ€‹

warning

Requires the SponsorBlock plugin on the player's node.

async setSponsorBlock(segments?: SponsorBlockSegment[]): Promise<void>

Sets the active SponsorBlock segment categories for this player. Defaults to [Sponsor, SelfPromo] if not provided.

Parametersโ€‹

Parameter Type Description Optional
segmentsSponsorBlockSegment[]The segment categories to activate. Defaults to [Sponsor, SelfPromo].

setTextChannelId()โ€‹

setTextChannelId(channel: string): this

Updates the text channel ID for this player.

Parametersโ€‹

Parameter Type Description Optional
channelstringThe new text channel ID.

Returnsโ€‹

Type Description
thisThe player instance.

setTrackRepeat()โ€‹

setTrackRepeat(repeat: boolean): this

Enables or disables track repeat. Disables queueRepeat and dynamicRepeat if currently active.

Parametersโ€‹

Parameter Type Description Optional
repeatbooleanWhether to enable track repeat.

Returnsโ€‹

Type Description
thisThe player instance.

setVoiceChannelId()โ€‹

setVoiceChannelId(channel: string): this

Updates the voice channel ID and reconnects the player to the new channel.

Parametersโ€‹

Parameter Type Description Optional
channelstringThe new voice channel ID.

Returnsโ€‹

Type Description
thisThe player instance.

setVolume()โ€‹

async setVolume(volume: number): Promise<this>

Sets the player volume. Valid range is 0โ€“1000, or 0โ€“500 when applyVolumeAsFilter is enabled.

Parametersโ€‹

Parameter Type Description Optional
volumenumberThe new volume level.

Returnsโ€‹

Type Description
Promise<this>The player instance.

setupVoiceReceiver()โ€‹

warning

Only available when the player is connected to a NodeLink node.

async setupVoiceReceiver(): Promise<void>

Opens a WebSocket connection to the NodeLink voice receiver endpoint for this player.


stop()โ€‹

async stop(amount?: number): Promise<this>

Stops the current track. If amount is greater than 1, also removes that many tracks from the front of the queue before stopping.

Parametersโ€‹

Parameter Type Description Optional
amountnumberThe number of upcoming tracks to also remove from the queue.

Returnsโ€‹

Type Description
Promise<this>The player instance.

updateVoice()โ€‹

async updateVoice(): Promise<void>

Sends the current voice state (token, endpoint, session ID, channel ID) to the Lavalink node. Called automatically after voice state updates.