Players
A player belongs to one guild. It owns the queue, filters, loop mode and voice connection, and it lives on one Lavalink node.
Create and join
Section titled “Create and join”// Create the player and wait until Lavalink has the voice connectionconst player = await raya.join({ guildId, voiceChannelId, textChannelId, // optional, handy for "Now playing" messages volume: 80, // optional overrides of playerDefaults selfDeaf: true,});raya.join() is raya.createPlayer() plus player.connect(). If the voice connection doesn’t arrive within voiceTimeout (15 seconds by default), it rejects with VOICE_TIMEOUT and cleans up the half-created player.
const existing = raya.getPlayer(guildId); // Player | undefinedconst player = raya.createPlayer({ guildId, voiceChannelId }); // returns the existing one if presentawait player.connect();Playback
Section titled “Playback”await player.play(); // next track from the queueawait player.play(track); // a specific trackawait player.play(track, { startTime: 30_000, endTime: 90_000 });await player.play(encodedString, { requester: user });
await player.skip(); // resolves with the new track, or null when the queue endedawait player.skip(3); // skip three tracksawait player.previous(); // back to the last played trackawait player.pause(); // pause(false) or resume() to continueawait player.seek(60_000); // clamped to the track lengthawait player.replay(); // seek(0)await player.stop(); // stop, keep the queueawait player.stop({ clearQueue: true });enqueue is the easiest way to handle a search result. It adds the first search hit or every playlist track, and starts playing if nothing is playing:
const result = await player.search('never gonna give you up', { requester: user });const { added, started } = await player.enqueue(result);Volume, loop and autoplay
Section titled “Volume, loop and autoplay”await player.setVolume(150); // 0-1000, where 100 is the original loudnessplayer.setLoop('track'); // 'off' | 'track' | 'queue'player.setAutoplay(true); // see the Autoplay guideplayer.setTextChannel(channelId);| Property | Description |
|---|---|
current |
The playing track, or null |
position |
Live position in ms, interpolated between Lavalink updates |
playing / paused / idle |
Playback state |
volume, loop, autoplay |
Current settings |
connected, ping |
Lavalink’s voice connection to Discord |
voiceChannelId, textChannelId |
Channels |
node |
The Lavalink node the player lives on |
queue, filters |
See queue and filters |
data |
A Map for your own values; included in snapshots |
player.data.set('djRole', roleId);const progress = `${player.position} / ${player.current?.info.length}`;await player.moveTo(otherChannelId); // move the botawait player.setSelfDeaf(false);await player.disconnect(); // leave voice but keep the player and queueWhen the bot is kicked or its channel is deleted, the player is destroyed automatically. Set playerDefaults.destroyOnVoiceDisconnect: false to keep it instead.
await player.moveNode('backup'); // keeps track, position, filters, volume and queueplayer.node.name;Destroy
Section titled “Destroy”await player.destroy(); // leave voice, stop audio, free it on Lavalinkawait raya.destroyPlayer(guildId); // same, by guild idYou can create a new player for the same guild right away: it waits until the old one has left before joining.