The Player
class represents a music player for a specific guild. It handles voice connections, track playback, queue management, audio filters, and additional features like lyrics and listening analysis when using NodeLink.
Players are created using the Manager's createPlayer
method and are automatically managed by the PlayerManager.
Configuration
When creating a player, you can specify several options:
interface IPlayerConfig {
guildId: string;
voiceChannelId: string;
textChannelId: string;
node?: string;
volume?: number;
loop?: "off" | "track" | "queue";
loopCount?: number;
autoPlay?: boolean;
autoLeave?: boolean;
}
Example:
const player = manager.createPlayer({
guildId: '123456789012345678',
voiceChannelId: '123456789012345678',
textChannelId: '123456789012345678',
volume: 80,
loop: 'off',
loopCount: 5,
autoPlay: true,
autoLeave: false
});
Properties
Property | Type | Description | Default |
---|---|---|---|
manager | Manager | The Manager instance that created this player | Required |
guildId | string | The ID of the guild this player belongs to | Required |
voiceChannelId | string | The ID of the voice channel | Required |
textChannelId | string | The ID of the text channel | Required |
region | string | The voice server region | Detected |
voiceState | IVoiceState | Voice connection state | {} |
autoPlay | boolean | Whether to auto-play next track | false |
autoLeave | boolean | Whether to auto-leave when empty | false |
connected | boolean | Whether connected to voice | false |
playing | boolean | Whether currently playing | false |
destroyed | boolean | Whether the player is destroyed | false |
paused | boolean | Whether playback is paused | false |
volume | number | Current volume level (0-1000) | 80 |
loop | TPlayerLoop | Loop mode ("off"/"track"/"queue") | "off" |
loopCount | number | Number of times to loop the current track or queue. undefined if not set. | undefined |
current | Track | Currently playing track | null |
previous | Track[] | Array of previously played tracks (history) | [] |
historySize | number | Maximum number of tracks to keep in history | 10 |
ping | number | Voice connection latency | 0 |
queue | Queue | Track queue instance | Created |
node | Node | Connected Lavalink node | Selected |
data | Record<string, unknown> | Custom data storage | {} |
filters | Filters | Audio filters instance | Created |
listen | Listen | Listening analysis (NodeLink) | Optional |
lyrics | Lyrics | Lyrics provider (NodeLink) | Optional |
The listen
and lyrics
properties are only available when the NodeLinkFeatures
option is enabled in the Manager or when connected to a NodeLink-compatible node.
Methods
connect
Connect to Voice
Connects the player to a voice channel.
Parameters
Returns & Example
Returns
• boolean
— Whether the connection was successful
player.connect({ setDeaf: true });
disconnect
Disconnect from Voice
Disconnects from the voice channel.
Returns & Example
Returns
• boolean
— Whether the disconnection was successful
player.disconnect();
play
Play Track
Starts or resumes playback. Handles blacklisted sources and attempts to find a suitable node if the current one is not compatible.
Parameters
id
and userData
properties. Returns & Example
Returns
• Promise<boolean>
— Whether playback started successfully
await player.play({
encoded: 'base64track',
requestedBy: '123456789',
position: 0
});
speak
Speak Text (TTS)
Converts text to speech and plays it. Supports different TTS providers. Requires a NodeLink server with appropriate capabilities.
Parameters
flowery
. false
, it will play immediately and then resume the current track. Returns & Example
Returns
• Promise<boolean>
— Whether the TTS playback was successful.
// Speak a message using default provider
await player.speak({ text: 'Hello, I am a bot.' });
// Speak in a specific language using Google TTS
await player.speak({ text: 'Hola, soy un bot.', provider: 'google', options: { language: 'es-ES' } });
// Add to queue instead of interrupting
await player.speak({ text: 'This will be added to the queue.', addToQueue: true });
replay
Replay Track
Replays the current track from the beginning.
Returns & Example
Returns
• Promise<boolean>
— Whether the replay was successful.
await player.replay();
back
Play Previous Track
Plays the previous track from the history. Skips blacklisted tracks.
Returns & Example
Returns
• Promise<boolean>
— Whether a previous track was played.
await player.back();
restart
Restart Player
Restarts the player and current track. Reconnects to the voice channel if necessary.
Returns & Example
Returns
• Promise<boolean>
— Whether the restart was successful
await player.restart();
transferNode
Transfer Node
Transfers the player to another node. Reconnects and resumes playback on the new node.
Parameters
Returns & Example
Returns
• Promise<boolean>
— Whether the transfer was successful
await player.transferNode('node-2');
pause
Pause Playback
Pauses the current playback.
Returns & Example
Returns
• boolean
— Whether the pause was successful
player.pause();
resume
Resume Playback
Resumes paused playback.
Returns & Example
Returns
• boolean
— Whether the resume was successful
player.resume();
stop
Stop Playback
Stops the current playback.
Parameters
Returns & Example
Returns
• boolean
— Whether the stop was successful
player.stop({ destroy: true });
skip
Skip Track
Skips to the next track or a specific position in the queue. Skips blacklisted tracks.
Parameters
Returns & Example
Returns
• Promise<boolean>
— Whether the skip was successful
await player.skip(2); // Skip to third track
skipChapter
Skip Chapter
Skips to a specific chapter in the current track. Requires chapter information to be available on the track.
Parameters
1
'count'
value
refers to a direct index
or a count
of chapters to skip from the current one. Returns & Example
Returns
• Promise<boolean>
— Whether the chapter skip was successful.
// Skip to the next chapter
await player.skipChapter();
// Skip to the third chapter (index 2)
await player.skipChapter(2, 'index');
seek
Seek Position
Seeks to a position in the current track.
Parameters
Returns & Example
Returns
• boolean
— Whether the seek was successful
player.seek(30000); // Seek to 30 seconds
shuffle
Shuffle Queue
Shuffles the current queue. Requires at least 2 tracks in the queue.
Returns & Example
Returns
• boolean
— Whether the shuffle was successful
// Only works if queue.size >= 2
player.shuffle();
setVolume
Set Volume
Sets the player volume.
Parameters
Returns & Example
Returns
• boolean
— Whether the volume was set successfully
player.setVolume(50); // Set to 50%
setLoop
Set Loop Mode
Sets the loop mode.
Parameters
0
for infinite loop. Returns & Example
Returns
• boolean
— Whether the loop mode was set successfully
player.setLoop('track'); // Loop current track indefinitely
player.setLoop('queue', 5); // Loop queue 5 times
player.setLoop('off'); // Disable loop
setAutoPlay
Set Auto Play
Sets auto-play behavior.
Parameters
Returns & Example
Returns
• boolean
— Whether auto-play was set successfully
player.setAutoPlay(true);
setAutoLeave
Set Auto Leave
Sets auto-leave behavior.
Parameters
Returns & Example
Returns
• boolean
— Whether auto-leave was set successfully
player.setAutoLeave(true);
setVoiceChannelId
Set Voice Channel
Changes the voice channel.
Parameters
Returns & Example
Returns
• boolean
— Whether the channel was set successfully
player.setVoiceChannelId('123456789');
setTextChannelId
Set Text Channel
Changes the text channel.
Parameters
Returns & Example
Returns
• boolean
— Whether the channel was set successfully
player.setTextChannelId('123456789');
set
Set Custom Data
Stores custom data in the player.
Parameters
Returns & Example
Returns
• void
player.set('customKey', 'customValue');
get
Get Custom Data
Retrieves custom data from the player.
Parameters
Returns & Example
Returns
• T
— The stored value
const value = player.get('customKey');
has
Has Custom Data
Checks if custom data exists in the player.
Parameters
Returns & Example
Returns
• boolean
— Whether the data exists
const exists = player.has('customKey');
delete
Delete Custom Data
Deletes custom data from the player.
Parameters
Returns & Example
Returns
• boolean
— Whether the deletion was successful
player.delete('customKey');
getSponsorBlockCategories
Get SponsorBlock Categories
Retrieves the currently configured SponsorBlock categories for a guild.
Parameters
This method takes no parameters.
Returns & Example
Returns
• Promise<string[]>
— An array of category strings.
const categories = await player.getSponsorBlockCategories();
console.log('SponsorBlock Categories:', categories);
setSponsorBlockCategories
Set SponsorBlock Categories
Sets the SponsorBlock categories for a guild.
Parameters
Returns & Example
Returns
• Promise<void>
await player.setSponsorBlockCategories(['sponsor', 'selfpromo']);
clearSponsorBlockCategories
Clear SponsorBlock Categories
Clears all configured SponsorBlock categories for a guild.
Parameters
This method takes no parameters.
Returns & Example
Returns
• Promise<void>
await player.clearSponsorBlockCategories();
getHistory
Get History
Retrieves the player's track history.
Parameters
Returns & Example
Returns
• Track[]
— An array of previously played tracks.
const history = player.getHistory();
const lastFive = player.getHistory(5);
getLyrics
Get Lyrics
Fetches lyrics for the current track or a specific encoded track using available lyrics plugins.
Parameters
Returns & Example
Returns
• Promise<ILavaLyricsObject | null>
— Lyrics data or null
if not found.
const lyrics = await player.getLyrics();
const specificLyrics = await player.getLyrics('base64encodedtrack');
subscribeLyrics
Subscribe to Live Lyrics
Subscribes to live lyrics updates for the player's guild. The provided callback will be invoked with each new lyrics line.
Parameters
Returns & Example
Returns
• Promise<void>
player.subscribeLyrics((line) => {
console.log(`Live Lyric: ${line.line} (at ${line.timestamp}ms)`);
});
unsubscribeLyrics
Unsubscribe from Live Lyrics
Unsubscribes from live lyrics updates for the player's guild.
Parameters
Returns & Example
Returns
• Promise<void>
player.unsubscribeLyrics();
console.log('Unsubscribed from live lyrics.');
searchLyrics
Search Lyrics
Searches for lyrics based on a query using available lyrics plugins.
Parameters
Returns & Example
Returns
• Promise<any[] | null>
— An array of search results or null
if no results found.
const searchResults = await player.searchLyrics({ query: 'Never Gonna Give You Up Rick Astley' });
if (searchResults && searchResults.length > 0) {
console.log('Found lyrics search results:', searchResults);
}
destroy
Destroy Player
Destroys the player and cleans up resources.
Parameters
Returns & Example
Returns
• boolean
— Whether the destruction was successful
player.destroy();