Skip to content

Queue

Defined in: src/structures/Queue.ts:131

new Queue(
guildId: string,
data?: Partial<StoredQueue>,
queueSaver?: QueueSaver,
queueOptions?: ManagerQueueOptions): Queue;

Defined in: src/structures/Queue.ts:148

Create a new Queue

ParameterTypeDescription
guildIdstringThe guild ID
dataPartial<StoredQueue>The data to initialize the queue with
queueSaver?QueueSaverThe queue saver to use
queueOptions?ManagerQueueOptions-

Queue

Property (defined in)TypeDefault valueDescription
current
(src/structures/Queue.ts:134)
Tracknull
options
(src/structures/Queue.ts:135)
objectundefined
options.maxPreviousTracks
(src/structures/Queue.ts:135)
number25
previous
(src/structures/Queue.ts:133)
Track[][]
tracks
([])
( \UnresolvedTrack \Track)[]
utils
(src/structures/Queue.ts:193)
objectundefinedUtils for a Queue
utils.destroy
(-)
() => Promise<boolean \void>undefined
utils.filterTracks
({ max?: number; min?: number; }; identifier?: string; isSeekable?: boolean; isStream?: boolean; sourceName?: string; title?: string; uri?: string; } )
(predicate: \{ author?: string; duration?: \number \
utils.findTrack
({ max?: number; min?: number; }; identifier?: string; isSeekable?: boolean; isStream?: boolean; sourceName?: string; title?: string; uri?: string; } )
(predicate: \{ author?: string; duration?: \number \
utils.save
(Save the current cached Queue on the database/server (overides the server))
() => Promise<boolean \void>undefined
utils.sync
(src/structures/Queue.ts:207)
(override: boolean, dontSyncCurrent: boolean) => Promise<void>undefinedSync the current queue database/server with the cached one
utils.toJSON
(src/structures/Queue.ts:253)
() => StoredQueueundefined
utils.totalDuration
(src/structures/Queue.ts:267)
() => numberundefinedGet the Total Duration of the Queue-Songs summed up
add(TrackOrTracks:
| UnresolvedTrack
| Track
| (
| UnresolvedTrack
| Track)[], index?: number): any;

Defined in: src/structures/Queue.ts:436

Add a Track to the Queue, and after saved in the “db” it returns the amount of the Tracks

ParameterTypeDescription
TrackOrTracks| UnresolvedTrack | Track | ( | UnresolvedTrack | Track)[]-
index?numberAt what position to add the Track

any

Queue-Size (for the next Tracks)


filter(predicate:
| {
author?: string;
duration?: | number
| {
max?: number;
min?: number;
};
identifier?: string;
isSeekable?: boolean;
isStream?: boolean;
sourceName?: string;
title?: string;
uri?: string;
}
| ((track:
| UnresolvedTrack
| Track, index: number) => boolean)): object[];

Defined in: src/structures/Queue.ts:741

Find tracks in the queue matching specific criteria. This method DOES NOT MUTATE the queue - it returns a new array without modifying the original queue.

ParameterTypeDescription
predicate| { author?: string; duration?: | number | { max?: number; min?: number; }; identifier?: string; isSeekable?: boolean; isStream?: boolean; sourceName?: string; title?: string; uri?: string; } | ((track: | UnresolvedTrack | Track, index: number) => boolean)Function to test each track, or an object with criteria to match

object[]

Array of matching tracks with their indexes

// Use the new method instead:
const artistTracks = player.queue.utils.filterTracks({ author: "Artist Name" });

find(predicate:
| {
author?: string;
duration?: | number
| {
max?: number;
min?: number;
};
identifier?: string;
isSeekable?: boolean;
isStream?: boolean;
sourceName?: string;
title?: string;
uri?: string;
}
| ((track:
| UnresolvedTrack
| Track, index: number) => boolean)): object;

Defined in: src/structures/Queue.ts:771

Find a single track in the queue matching specific criteria. This method DOES NOT MUTATE the queue - it searches without modifying the original queue.

ParameterTypeDescription
predicate| { author?: string; duration?: | number | { max?: number; min?: number; }; identifier?: string; isSeekable?: boolean; isStream?: boolean; sourceName?: string; title?: string; uri?: string; } | ((track: | UnresolvedTrack | Track, index: number) => boolean)Function to test each track, or an object with criteria to match

object

First matching track with its index, or null if not found

NameTypeDefined in
indexnumbersrc/structures/Queue.ts:784
track| UnresolvedTrack | Tracksrc/structures/Queue.ts:784
// Use the new method instead:
const track = player.queue.utils.findTrack({ author: "Artist Name" });

getTracks(start: number, end?: number): (
| UnresolvedTrack
| Track)[];

Defined in: src/structures/Queue.ts:910

Get a range of tracks from the queue. This method DOES NOT MUTATE the queue - it returns a new array slice, similar to Array.slice().

ParameterTypeDescription
startnumberStart index (inclusive)
end?numberEnd index (exclusive)

( | UnresolvedTrack | Track)[]

Array of tracks in the specified range

// Get tracks 5-15
const tracks = player.queue.getTracks(5, 15);
// Get first 10 tracks
const firstTen = player.queue.getTracks(0, 10);

remove<T>(removeQueryTrack: T): Promise<{
removed: (
| UnresolvedTrack
| Track)[];
}>;

Defined in: src/structures/Queue.ts:567

Remove stuff from the queue.tracks array

  • single Track | UnresolvedTrack
  • multiple Track | UnresovedTrack
  • at the index or multiple indexes
  • Since v2.7 the removed tracks get unshifted into the previous queue state instead of pushed (indexed at the start instead of end - as it should)
Type Parameter
T extends | number | UnresolvedTrack | UnresolvedTrack[] | Track | Track[] | number[] | ( | number | UnresolvedTrack | Track)[]
ParameterTypeDescription
removeQueryTrackT-

Promise<{ removed: ( | UnresolvedTrack | Track)[]; }>

null (if nothing was removed) / { removed } where removed is an array with all removed elements

// remove single track
const track = player.queue.tracks[4];
await player.queue.remove(track);
// if you already have the index you can straight up pass it too
await player.queue.remove(4);
// if you want to remove multiple tracks, e.g. from position 4 to position 10 you can do smt like this
await player.queue.remove(player.queue.tracks.slice(4, 10)) // get's the tracks from 4 - 10, which then get's found in the remove function to be removed
// I still highly suggest to use .splice!
await player.queue.splice(4, 10); // removes at index 4, 10 tracks
await player.queue.splice(1, 1); // removes at index 1, 1 track
await player.queue.splice(4, 0, ...tracks) // removes 0 tracks at position 4, and then inserts all tracks after position 4.

shiftPrevious(): Promise<Track>;

Defined in: src/structures/Queue.ts:722

Shifts the previous array, to return the last previous track & thus remove it from the previous queue

Promise<Track>

// example on how to play the previous track again
const previous = await player.queue.shiftPrevious(); // get the previous track and remove it from the previous queue array!!
if(!previous) return console.error("No previous track found");
await player.play({ clientTrack: previous }); // play it again

shuffle(): Promise<number>;

Defined in: src/structures/Queue.ts:407

Shuffles the current Queue, then saves it

Promise<number>

Amount of Tracks in the Queue


sortBy(sortBy:
| "title"
| "author"
| "duration"
| ((a:
| UnresolvedTrack
| Track, b:
| UnresolvedTrack
| Track) => number), order?: "asc" | "desc"): Promise<Queue>;

Defined in: src/structures/Queue.ts:809

Sort the queue tracks by a specific property. ⚠️ This method MUTATES the queue - it modifies the original queue in place.

ParameterTypeDefault valueDescription
sortBy| "title" | "author" | "duration" | ((a: | UnresolvedTrack | Track, b: | UnresolvedTrack | Track) => number)undefinedProperty to sort by or custom comparator function
order"asc" | "desc""asc"Sort order: ‘asc’ or ‘desc’ (default: ‘asc’)

Promise<Queue>

The queue instance for chaining

// Sort by duration (shortest first)
await player.queue.sortBy("duration", "asc");
// Sort by title alphabetically (Z-A)
await player.queue.sortBy("title", "desc");
// Custom sorting
await player.queue.sortBy((a, b) => {
return a.info.title.localeCompare(b.info.title);
});

splice(
index: number,
amount: number,
TrackOrTracks?:
| UnresolvedTrack
| Track
| (
| UnresolvedTrack
| Track)[]): any;

Defined in: src/structures/Queue.ts:483

Splice the tracks in the Queue

ParameterTypeDescription
indexnumberWhere to remove the Track
amountnumberHow many Tracks to remove?
TrackOrTracks?| UnresolvedTrack | Track | ( | UnresolvedTrack | Track)[]Want to Add more Tracks?

any

Spliced Track


toSortedBy(sortBy:
| "title"
| "author"
| "duration"
| ((a:
| UnresolvedTrack
| Track, b:
| UnresolvedTrack
| Track) => number), order?: "asc" | "desc"): (
| UnresolvedTrack
| Track)[];

Defined in: src/structures/Queue.ts:863

Get a sorted copy of the queue tracks without modifying the original queue. This method DOES NOT MUTATE the queue - it returns a new sorted array, similar to Array.toSorted().

ParameterTypeDefault valueDescription
sortBy| "title" | "author" | "duration" | ((a: | UnresolvedTrack | Track, b: | UnresolvedTrack | Track) => number)undefinedProperty to sort by or custom comparator function
order"asc" | "desc""asc"Sort order: ‘asc’ or ‘desc’ (default: ‘asc’)

( | UnresolvedTrack | Track)[]

A new sorted array of tracks (does not modify the queue)

// Get sorted copy by duration (shortest first)
const sortedTracks = player.queue.toSortedBy("duration", "asc");
// Original queue remains unchanged
// Get sorted copy by title alphabetically (Z-A)
const sortedByTitle = player.queue.toSortedBy("title", "desc");
// Custom sorting
const customSorted = player.queue.toSortedBy((a, b) => {
return a.info.title.localeCompare(b.info.title);
});