Entity Serialization and Deserialization
Learn how to serialize or deserialize discord-player entities
Serialization and Deserialization in discord-player is the process of converting a track or playlist object into a plain json object and vice versa.
Saving tracks or playlists in a database
You may want to save tracks or playlists in a database to be able to retrieve them later. This also helps your users to save their favorite tracks or playlists, or create a custom playlist. Discord Player offers a built-in way to save and retrieve tracks or playlists in a database.
Track
s and Playlist
s only.Saving tracks
To save a track, you will have to first convert Discord Player track object into a plain json object. Discord Player exports a function named
serialize
which takes a track object and returns a plain json object.
You can also encode the track object into a base64 string using the encode
function.
Retrieving tracks
To retrieve a track, you will have to first convert the plain json object into a Discord Player track object. Discord Player exports a function named deserialize
which takes a plain json object and returns a Discord Player track object.
You can also decode the base64 string into a plain json object using the decode
function.
Saving playlists
You can use the same method as above to save or retrieve playlists.
Saving queue
Discord Player does not offer queue serialization. But you can use the following method to serialize tracks under the queue.