Queues
Create queues, add tracks, and control repeat, shuffle, and ordering.
A GuildQueue belongs to one guild and decides which track plays next. Remedia plays the audio. The queue keeps the current track, the upcoming tracks, and the history.
Create or get a queue
import { QueueRepeatMode } from 'discord-player';
const queue = await player.createQueue(guildId, {
maxSize: 100,
metadata: { textChannelId },
history: {
maxHistorySize: 50,
},
playback: {
repeatMode: QueueRepeatMode.OFF,
},
});
const existing = player.getQueue(guildId); // null when there is no queueInitialization options apply only when the queue is created. For per-call session volume or filtering, use connectionOptions in player.play() or queue.play(), or pass them directly to queue.connect(). player.play() creates a queue for you, so you usually only call getQueue().
maxSize limits upcoming tracks. The current track does not count toward it.
Add and play tracks
The usual route is player.play(), which searches, queues, and starts playback:
const { queue, track } = await player.play({ guildId, channelId }, query);If you already have Track objects, use the queue directly:
await queue.play(track, { connectionOptions: { channelId } }); // Queue it and start if idle
queue.addTrack(track); // Upcoming only
queue.addTracks(moreTracks);channelId can be left out when the queue is already connected.
Search results queue one track
player.play() and queue.play() queue only the first track of a SearchResult. To queue every result, call
queue.addTracks(searchResult.tracks).
Read queue state
| Property | Value |
|---|---|
queue.currentTrack | The playing or paused track, otherwise null |
queue.tracks | Upcoming tracks. Call toArray() for an array |
queue.size | Number of upcoming tracks |
queue.estimatedDuration | Total duration of upcoming tracks in milliseconds |
queue.isPlaying() | true while playing, including when paused |
queue.history | Previous tracks |
Repeat modes
import { QueueRepeatMode } from 'discord-player';
queue.repeatMode = QueueRepeatMode.TRACK;| Mode | Behavior |
|---|---|
OFF | Play the upcoming tracks, then finish |
TRACK | Repeat the current track until you change the mode or skip |
QUEUE | Move each finished track to the end of the queue |
AUTOPLAY | Ask the track's source for related tracks when the queue runs out |
Autoplay
With AUTOPLAY, the queue calls the source's track.related operation after the last track finishes or is manually skipped. Skip still emits playerSkip, without a natural playerFinish event. Stops, disconnects, destruction, and canceled transitions do not start discovery. With crossfade enabled, it starts discovery earlier when Remedia requests preparation and no upcoming track exists. Discovery receives a bounded metadata snapshot of retained history plus the outgoing seed track, including before that track finishes. Remote source hosts receive the same snapshot. Legacy extractors can query history.tracks with some(), find(), or toArray(); it does not expose queue controls. The willAutoPlay callback can therefore run while the current track is still playing. If discovery finishes too late for crossfade, the selected track starts normally. Discovery tries the originating provider first, then eligible providers in priority order until one returns candidates other than the seed. Empty results allow fallback; failures remain errors. Remote discovery stays on the originating authorized host and preserves the selected provider identity. If all providers return nothing, playback ends.
autoplayTimeoutMs (30 seconds by default) bounds discovery and asynchronous selection together. A listener must call done(track) or done(null) before that deadline. Returning null from selection ends AutoPlay. Errors identify discovery, selection, source resolution, staging, or playback transition, with operation and deployment identity and elapsed time. Cancellation caused by queue controls ignores late results.
To pick the related track yourself, listen for willAutoPlay and call done with the track, or null to stop:
player.events.on('willAutoPlay', (queue, tracks, done) => {
done(tracks[0] ?? null);
});Without a listener, the queue prefers a track that has not played yet. Skipping, stopping, or changing the queue cancels a pending selection.
Shuffle
queue.enableShuffle(); // Picks the next track at random each time
queue.disableShuffle();
queue.toggleShuffle();Shuffle picks the next upcoming track at random. It does not reorder the queue and does not change history. Turning it off does not restore an earlier order.
Change the order
All of these work on upcoming tracks only:
| Method | Effect |
|---|---|
removeTrack(track) | Remove a track |
moveTrack(track, index) | Move a track |
swapTracks(a, b) | Swap two tracks |
insertTrack(track, index) | Insert one track |
prepend(tracks) and append(tracks) | Add to the start or end |
clear() | Remove upcoming tracks and history. The current track keeps playing |
A track can be a Track, a track ID, or an index.
Delete a queue
await queue.destroy(); // or player.deleteQueue(guildId)This stops playback, leaves voice, and clears the queue. A later player.play() creates a new queue.
Continue reading
Control playbackConnection defaults and per-call overrides
nodeOptions.connectionOptions in player.play(), and connectionOptions in
player.createQueue() or player.queues.create(), store defaults when the queue
is first created. Later calls do not replace those defaults.
Root connectionOptions in player.play() and queue.play() uses the same
GuildQueueConnectionOptions type. queue.connect() adds a required channelId
and optional cancellation signal. The shared configuration supports selfDeaf,
selfMute, nodeId, selectNode, connectTimeoutMs, volume (0–200),
filterGraph (including null to clear), and enableFallbackSeeking.
For a new session, explicit call options override queue connection defaults, then playback volume/filter defaults and Remedia defaults apply. On an existing session, omitted options retain its current settings. Explicit voice flags, volume, filters, and channel moves apply to that session. Connection deadlines apply when voice negotiation is needed. Node selection applies at creation; an existing session cannot switch nodes.
enableFallbackSeeking defaults to false in Remedia and is fixed for the
session lifetime. Repeating the same effective value succeeds. Changing it
throws before applying other controls or adding the track. Destroying the
session allows the next connection to use the queue defaults and any new call
overrides.
const connectionOptions = { selfDeaf: true, enableFallbackSeeking: false };
await player.play(channel, trackA, {
nodeOptions: { connectionOptions },
connectionOptions,
});
await player.play(channel, trackB, { connectionOptions });