Playlist
A playlist and its tracks, independent of any Discord client library.
class Playlist implements Iterable<Track>, Serializable<SerializedPlaylist>A playlist and its tracks, independent of any Discord client library.
Constructors
constructor
constructor(data?: PlaylistData)Create a playlist from public metadata and Track entries.
Parameters
| Name | Type | Description |
|---|---|---|
| data? | PlaylistData | Playlist metadata and entries in source order. |
constructor(player: LegacyPlayerContext, data: PlaylistData)Legacy playlist construction.
Parameters
| Name | Type | Description |
|---|---|---|
| player | LegacyPlayerContext | Legacy Player; retained only for call compatibility. |
| data | PlaylistData | Playlist metadata. |
Properties
idreadonly
readonly id: stringStable source playlist identifier.
url
url: stringSource page URL.
title
title: stringDisplay title.
description
description: stringPlaylist description.
thumbnail
thumbnail: stringThumbnail URL.
type
type: "album" | "playlist"Album or playlist classification.
source
source: stringSource name.
tracks
tracks: Track<unknown>[]Tracks in this playlist, in source order.
Accessors
estimatedDurationreadonly
readonly get estimatedDuration(): numberSum of known Track durations in milliseconds.
Returns
number
durationFormattedreadonly
readonly get durationFormatted(): stringHuman-readable sum of known Track durations.
Returns
string
Methods
toJSON
toJSON(withTracks: boolean = true): PlaylistJSONReturn a JSON-compatible playlist representation.
Parameters
| Name | Type | Description |
|---|---|---|
| withTracks | booleanDefault: true | Whether to include Track data in the result. |
Returns
PlaylistJSON
serialize
Implementation of Serializable.serialize
serialize(): SerializedPlaylistSerialize public Playlist metadata and ordered Tracks using schema version 1. Track serialization omits each Track's parent Playlist reference to prevent recursive payloads.
Returns
SerializedPlaylist
A versioned Playlist persistence payload.
[iterator]
Implementation of Iterable.[iterator]
Static methods
deserializestatic
static deserialize(data: PlaylistData): PlaylistReconstruct a Playlist from public data and link its Tracks to the restored Playlist.
Parameters
| Name | Type | Description |
|---|---|---|
| data | PlaylistData | Playlist fields and optional Track entries. |
Returns
Playlist
fromSerializedstatic
static fromSerialized(serialized: SerializedPlaylist): PlaylistReconstruct a Playlist from a validated versioned persistence payload.
Parameters
| Name | Type | Description |
|---|---|---|
| serialized | SerializedPlaylist | Versioned Playlist payload containing ordered Track entities. |
Returns
Playlist
A Playlist with Track instances linked to their parent Playlist.