Skip to main content
Version: v2.10.5

TrackUtils

Table of Contents​

Class Definition​

export abstract class TrackUtils {}
info

TrackUtils is an abstract utility class. All members are static — it cannot be instantiated directly.

Properties​

Property Type Description
trackPartialTrackPartial[] | nullThe list of track properties to retain. null means all properties are kept.

Methods​

build()​

static build<T = AnyUser>(data: TrackData, requester?: T, isAutoplay?: boolean): Track

Builds a Track object from raw Lavalink track data.

Parameters​

Parameter Type Description Optional
dataTrackDataThe raw encoded track data from Lavalink.
requesterTThe user who requested the track.
isAutoplaybooleanWhether the track was queued by autoplay. Defaults to false.

Returns​

Type Description
TrackThe built track object.

init()​

static init(manager: Manager): void

Initializes the static Manager reference used by TrackUtils. Called internally by the manager.

Parameters​

Parameter Type Description Optional
managerManagerThe Manager instance.

isErrorOrEmptySearchResult()​

static isErrorOrEmptySearchResult(result: SearchResult): result is ErrorOrEmptySearchResult

Type guard that returns true if the search result has a load type of Empty or Error.

Parameters​

Parameter Type Description Optional
resultSearchResultThe search result to check.

Returns​

Type Description
booleantrue if the result is empty or an error.

isTrack()​

static isTrack(track: unknown): track is Track

Type guard that checks whether the given value is a valid Track object (has track, title, and uri as strings).

Parameters​

Parameter Type Description Optional
trackunknownThe value to check.

Returns​

Type Description
booleantrue if the value is a valid Track.

isTrackArray()​

static isTrackArray(value: unknown): value is Track[]

Type guard that checks whether the given value is an array where every element is a valid Track.

Parameters​

Parameter Type Description Optional
valueunknownThe value to check.

Returns​

Type Description
booleantrue if the value is a Track[].

revive()​

static revive(track: Track): Track

Re-attaches the displayThumbnail method to a deserialized track (e.g. after loading from storage).

Parameters​

Parameter Type Description Optional
trackTrackThe track to revive.

Returns​

Type Description
TrackThe revived track.

setTrackPartial()​

static setTrackPartial(partial: TrackPartial[]): void

Sets which track properties are kept when building tracks. Any properties not in the list are deleted from the built object. The track property is always preserved.

Parameters​

Parameter Type Description Optional
partialTrackPartial[]The array of property names to retain on built tracks.

validate()​

static validate(value: unknown): value is Track | Track[]

Returns true if the given value is a valid Track or a valid Track[].

Parameters​

Parameter Type Description Optional
valueunknownThe track or array of tracks to validate.

Returns​

Type Description
booleantrue if the value is a valid Track or Track[].