Skip to main content
Version: v2.10.5

MemoryQueue

Table of Contents​

Class Definition​

export class MemoryQueue extends Array<Track> implements IQueue {}

Properties​

Property Type Description
currentTrack | nullThe current track.
guildIdstringThe guild ID.
managerManagerThe Manager instance.
previousTrack[] | []The previous tracks.

Constructor​

new MemoryQueue(guildId: string, manager: Manager)
Parameter Type Description Optional
guildIdstringThe guild ID
managerManagerThe Manager instance.

Methods​

add()​

add(track: Track | Track[], offset?: number): void

Adds a track or an array of tracks to the queue.

Parameters​

Parameter Type Description Optional
trackTrack | Track[]The track or an array of tracks to add to the queue.
offsetnumberThe offset to add the track at.

addPrevious()​

addPrevious(track: Track | Track[]): void

Adds one or more tracks to the "previous" history list.

Parameters​

Parameter Type Description Optional
trackTrack | Track[]The track to add to the "previous" history list.

clear()​

clear(): void

Clears the queue.


clearPrevious()​

clearPrevious(): void

Clears the "previous" history list.


dequeue()​

dequeue(): Track | undefined

Removes the first element from the queue.

Returns​

Type Description
Track | undefinedThe first element in the queue, or undefined if the queue is empty.

destroy()​

destroy(): void

Destroys the queue and releases all resources. After calling this method, the queue must not be used again.


duration()​

duration(): number

Returns the total duration of the queue.

Returns​

Type Description
numberThe total duration of the queue in milliseconds.

enqueueFront()​

enqueueFront(track: Track | Track[]): void

Adds a track or an array of tracks to the front of the queue.

Parameters​

Parameter Type Description Optional
trackTrack | Track[]The track or an array of tracks to add to the queue.

everyAsync()​

everyAsync(callback: (track: Track, index: number, array: Track[]) => boolean): boolean

Tests whether all elements in the queue pass the test implemented by the provided function.

Parameters​

Parameter Type Description Optional
callbackFunctionThe callback function.

Returns​

Type Description
booleantrue if the callback function returns a truthy value for every element in the queue, otherwise false.

filterAsync()​

filterAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Track | undefined

Filters the queue.

Parameters​

Parameter Type Description Optional
callbackFunctionThe callback function.

Returns​

Type Description
Track | undefinedThe first element in the queue, or undefined if the queue is empty.

findAsync()​

findAsync(callback: (track: Track, index: number, array: Track[]) => boolean): Track | undefined

Returns the first element in the queue that satisfies the provided testing function.

Parameters​

Parameter Type Description Optional
callbackFunctionThe callback function.

Returns​

Type Description
Track | undefinedThe first element in the queue, or undefined if the queue is empty.

getCurrent()​

getCurrent(): Track | null

Returns the currently playing track.

Returns​

Type Description
Track | nullThe current track, or null if no track is playing.

getPrevious()​

getPrevious(): Track[]

Returns the previous tracks.

Returns​

Type Description
Track[]The previous tracks.

getSlice()​

getSlice(start?: number, end?: number): Track[]

Returns a slice of the queue.

Parameters​

Parameter Type Description Optional
startnumberStart index of the range of tracks to remove.
endnumberEnd index (exclusive) of the range of tracks to remove.

Returns​

Type Description
Track[]The tracks in the queue.

getTracks()​

getTracks(): Track[]

Returns the tracks in the queue.

Returns​

Type Description
Track[]The tracks in the queue.

mapAsync()​

mapAsync<T>(callback: (track: Track, index: number, array: Track[]) => T): T[]

Maps the queue to an array of values.

Parameters​

Parameter Type Description Optional
callbackFunctionThe callback function.

modifyAt()​

modifyAt(start: number, deleteCount = 0, ...items: Track[]): Track[]

Modifies a range of tracks in the queue.

Parameters​

Parameter Type Description Optional
startnumberStart index of the range of tracks to remove.
deleteCountnumberNumber of tracks to remove.
itemsTrack[]Array of tracks to insert.

Returns​

Type Description
Track[]The tracks in the queue.

popPrevious()​

popPrevious(): Track | null

Removes and returns the last track from the "previous" history list.

Returns​

Type Description
Track | nullThe last track in the "previous" history list, or null if the list is empty.

remove()​

remove(position?: number): Track[]
remove(start: number, end: number): Track[]

Removes a track or a range of tracks from the queue.

Parameters​

Parameter Type Description Optional
positionnumberIndex of the track to remove.
startnumberStart index of the range of tracks to remove.
endnumberEnd index (exclusive) of the range of tracks to remove.

Returns​

Type Description
Track[]The removed track(s).

roundRobinShuffle()​

roundRobinShuffle(): void

Shuffles the queue to play tracks requested by each user one by one.


setCurrent()​

setCurrent(track: Track | null): void

Sets the currently playing track.

Parameters​

Parameter Type Description Optional
trackTrack | nullThe track to set as the current track.

setPrevious()​

setPrevious(tracks: Track[]): void

Sets the previous tracks.

Parameters​

Parameter Type Description Optional
tracksTrack[]The previous tracks to set.

shuffle()​

shuffle(): void

Shuffles the queue.


size()​

size(): number

Returns the size of the queue not including the current track.

Returns​

Type Description
numberThe size of the queue.

someAsync()​

someAsync(callback: (track: Track, index: number, array: Track[]) => boolean): boolean

Tests whether at least one element in the queue passes the test implemented by the provided function.

Parameters​

Parameter Type Description Optional
callbackFunctionThe callback function.

Returns​

Type Description
booleantrue if the callback function returns a truthy value for at least one element in the queue, otherwise false.

totalSize()​

totalSize(): number

Returns the total size of the queue.

Returns​

Type Description
numberThe total size of the queue.

userBlockShuffle()​

userBlockShuffle(): void

Shuffles the queue to play tracks requested by each user one block at a time.