Discord Player

Track

A Discord-library-agnostic track model. Source resolution belongs to a source plugin.

You are reading the v8 docsDev
ClassTypeScript@discord-player/plugin-host
View sourcepackages/plugin-host/src/structures/track.ts:62
class Track<Metadata = unknown> implements Serializable<SerializedTrack>

A Discord-library-agnostic track model. Source resolution belongs to a source plugin.

Constructors

constructor

constructor<Metadata = unknown>(player: LegacyPlayerContext, data: TrackData<Metadata>)

Legacy construction; Player is not needed by modern source plugins.

Parameters

NameTypeDescription
playerLegacyPlayerContext

Owning legacy Player.

dataTrackData<Metadata>

Legacy metadata and local engine payload.

constructor<Metadata = unknown>(data?: TrackData<Metadata>)

Create a modern data-only track.

Parameters

NameTypeDescription
data?TrackData<Metadata>

Track metadata and portable provider identity.

Properties

idreadonly

readonly id: string

Stable identifier for this Track instance.

title

title: string

Display title.

author

author: string

Track author or artist.

description

description: string

Track description.

url

url: string

Source page URL.

thumbnail

thumbnail: string

Thumbnail URL.

duration

duration: string

Human-readable duration.

views

views: number

View or play count when available.

requestedBy

requestedBy: TrackRequester | null

User or application identity that requested this track.

source

source: string

Provider-defined source name or identifier.

live

live: boolean

Whether this is a live stream without a fixed duration.

playlist

playlist: Playlist | null

Playlist containing this track, when present.

sourceReferenceoptional

sourceReference?: ProviderReference

Portable source identity used by the plugin host.

lyricsReferenceoptional

lyricsReference?: ProviderReference

Optional portable lyrics provider affinity.

sourceStateoptional

sourceState?: string

Opaque, expiring host state hint. Excluded from toJSON() and serialize(); retain only in memory.

rawreadonly

readonly raw: Record<string, any>

Process-local v7 raw payload. Never serialized.

queryTypeoptional

queryType?: string

Legacy query hint.

cleanTitle

cleanTitle: string

Legacy display title.

playerreadonlyoptional

readonly player?: LegacyPlayerContext

Legacy owning Player, absent for modern data-only tracks.

bridgedExtractor

bridgedExtractor: BaseExtractor<any> | null

Process-local v7 bridge provider; never used by core queue playback.

bridgedTrack

bridgedTrack: Track<unknown> | null

Process-local v7 bridge metadata; never persisted.

Accessors

extractor

get extractor(): BaseExtractor<any> | null

Compatibility extractor reference. Assigning it stamps a portable provider identity.

Returns

BaseExtractor<any> | null

set extractor(value: BaseExtractor<any> | null)

requester

get requester(): TrackRequester | null

Alias for the v7 requestedBy field.

Returns

TrackRequester | null

set requester(value: TrackRequester | null)

metadata

get metadata(): Metadata | null

Arbitrary source-plugin metadata.

Returns

Metadata | null

set metadata(value: Metadata | null)

hasMetadatareadonly

readonly get hasMetadata(): boolean

Whether source-plugin metadata is present.

Returns

boolean

durationMSreadonly

readonly get durationMS(): number

Track duration in milliseconds, parsed from duration when not supplied.

Returns

number

Methods

requestMetadata

requestMetadata(): Promise<Metadata | null>

Request legacy metadata; the callback remains process-local.

Returns

Promise<Metadata | null>

setMetadata

setMetadata(value: Metadata | null): void

Replace legacy metadata.

Parameters

NameTypeDescription
valueMetadata | null

New metadata.

Returns

void

asMetadata

asMetadata<NewMetadata>(): Track<NewMetadata>

Cast this Track to a different metadata type without copying it.

Returns

Track<NewMetadata>

The same Track reference with a different metadata type.

toString

toString(): string

Format the Track as title by author, omitting the author when empty.

Returns

string

toJSON

toJSON(hidePlaylist: boolean = false): TrackJSON<Metadata>

Return a JSON-compatible Track representation.

Parameters

NameTypeDescription
hidePlaylistbooleanDefault: false

When true, omit playlist metadata to prevent nested playlist serialization.

Returns

TrackJSON<Metadata>

serialize

Implementation of Serializable.serialize

serialize(): SerializedTrack

Serialize public Track data using schema version 1. Requesters are reduced to their string identity, Playlist links are omitted, and metadata must be JSON-safe.

Returns

SerializedTrack

A versioned Track persistence payload.

Static methods

deserializestatic

static deserialize<Metadata = unknown>(data: TrackData<Metadata>): Track<Metadata>

Construct a Track from public model data without resolving its media source.

Parameters

NameTypeDescription
dataTrackData<Metadata>

Track fields and optional source-plugin metadata.

Returns

Track<Metadata>

A Track instance reconstructed from the provided fields.

fromSerializedstatic

static fromSerialized(serialized: SerializedTrack): Track

Reconstruct a Track from a validated versioned persistence payload.

Parameters

NameTypeDescription
serializedSerializedTrack

Versioned Track payload.

Returns

Track

A Track instance with no reconstructed source-plugin playback state.

On this page