Skip to main content
Version: v2.10.0

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[].