Star ✨ on GitHub

Queue

Manages the list of tracks waiting to be played. Supports adding, removing, shuffling, and manipulating tracks.

The Queue class is a specialized array-like structure that holds the tracks scheduled for playback. It provides helper methods for common music bot operations like shuffling, moving tracks, or clearing the queue.

Properties

Queue Properties

State and contents of the track queue.

State

sizenumber

The number of tracks currently in the queue.

durationnumber

The total duration of all tracks in the queue (in milliseconds).

remainingDurationnumber

Duration of the queue + the remaining time of the currently playing track.

isEmptyboolean

True if the queue has no tracks.

Accessors

firstTrack | undefined

The first track in the queue (next to play).

lastTrack | undefined

The last track in the queue.

allTrack[]

Returns a copy of all tracks in the queue array.

Methods

add(track)

Adds one or more tracks to the end of the queue. Respects maxSize and allowDuplicates settings.

trackTrack | Track[] required

The track(s) to add.

Example
// Add a single track
player.queue.add(track);

// Add multiple tracks (e.g. playlist)
player.queue.add(playlist.tracks);

remove(index)

remove(index)#

Removes and returns the track at the specified index.

indexnumber

The index to remove. Defaults to 0.

Example
const removed = player.queue.remove(2);
console.log(`Removed: ${removed.title}`);

clear()

clear()#

Removes all tracks from the queue.

Example
player.queue.clear();

shuffle()

shuffle()#

Randomly shuffles the order of tracks in the queue.

Example
player.queue.shuffle();

insert(index, track)

Inserts one or more tracks at a specific position in the queue.

indexnumber required

The index to insert at.

trackTrack | Track[] required

The track(s) to insert.

Example
// Add "Next Song" to the top of the queue
player.queue.insert(0, nextSong);

move(from, to)

move(from, to)#

Moves a track from one position to another.

fromnumber required

The index of the track to move.

tonumber required

The index where the track should be placed.

Example
// Move the last song to be the next one
player.queue.move(player.queue.size - 1, 0);

get(position)

get(position)#

Retrieves the track at a specific index without removing it.

positionnumber required

The index of the track.

Example
const nextSong = player.queue.get(0);

has(track)

has(track)#

Checks if a specific track object exists in the queue.

trackTrack required

The track object to check.

Example
if (player.queue.has(myTrack)) {
    console.log("Track is already queued.");
}

removeDuplicates()

Removes duplicate tracks from the queue based on their encoded string. Returns true if duplicates were found and removed.

Example
player.queue.removeDuplicates();

reverse()

reverse()#

Reverses the order of the queue.

Example
player.queue.reverse();

sortByTitle()

Sorts the queue alphabetically by track title (A-Z).

Example

player.queue.sortByTitle();

sortByAuthor()

Sorts the queue alphabetically by artist/author name (A-Z).

Example

player.queue.sortByAuthor();

sortByDuration()

Sorts the queue by track duration (shortest to longest).

Example

player.queue.sortByDuration();