Star ✨ on GitHub

REST API

API reference for the REST API in Moonlink.js

REST Class

The class responsible for managing HTTP requests to the Lavalink server. It is instantiated via a Node instance.

new REST(node: Node)

Overview

Properties

Core properties of the REST class.

Available Properties

PropertyTypeDescription
nodeNodeThe associated Node instance.
urlstringBase URL for requests to the Lavalink server.
defaultHeadersRecord<string, string>Default headers used for all requests.

Configuration

The REST class is configured through the Node instance it is associated with. It inherits connection details and authentication from the Node.

Methods

loadTracks

loadTracksmethod

Load Tracks

Loads tracks from an identifier. Supports direct URLs, and special prefixes for TTS sources.

Parameters
sourcerequiredstring
The search source (youtube, soundcloud, flowerytts, tts, etc.)
queryrequiredstring
The search query or direct URL.

Returns & Example

ReturnsPromise<IRESTLoadTracks>

// Load a track from YouTube
const result = await rest.loadTracks('youtube', 'Never Gonna Give You Up');

// Load a playlist
const result = await rest.loadTracks('youtube', 'https://youtube.com/playlist?list=...');

// Load a TTS track
const ttsResult = await rest.loadTracks('flowerytts', 'Hello, world!');

update

updatemethod

Update Player

Updates a player's state on the Lavalink server.

Parameters
datarequiredIRESTOptions
An object containing guildId and data for the player update.

Returns & Example

ReturnsPromise<unknown>

await rest.update({
guildId: '123456789',
data: {
  track: 'base64EncodedTrack',
  volume: 100
}
});

destroy

destroymethod

Destroy Player

Removes a player from the Lavalink server.

Parameters
guildIdrequiredstring
Discord guild ID

Returns & Example

ReturnsPromise<unknown>

await rest.destroy('123456789');

getInfo

getInfomethod

Get Info

Gets information about the Lavalink server.

Returns & Example

ReturnsPromise<unknown>

const info = await rest.getInfo();

getStats

getStatsmethod

Get Stats

Gets statistics from the Lavalink server.

Returns & Example

ReturnsPromise<unknown>

const stats = await rest.getStats();

getVersion

getVersionmethod

Get Version

Gets the Lavalink server version.

Returns & Example

ReturnsPromise<unknown>

const version = await rest.getVersion();

getLyrics

getLyricsmethod

Get Lyrics

Gets the lyrics for a track.

Parameters
datarequiredObject
Track data
data.encodedrequiredstring
Base64 encoded track

Returns & Example

ReturnsPromise<IRESTGetLyrics>

const lyrics = await rest.getLyrics({ encoded: 'base64EncodedTrack' });

updateSession

updateSessionmethod

Update Session

Updates a session on the Lavalink server.

Parameters
sessionIdrequiredstring
Session ID
datarequiredany
Session data

Returns & Example

ReturnsPromise<any>

await rest.updateSession('session-123', { timeout: 60000 });

decodeTrack

decodeTrackmethod

Decode Track

Decodes a base64 encoded track.

Parameters
encodedTrackrequiredstring
Base64 encoded track

Returns & Example

ReturnsPromise<any>

const trackInfo = await rest.decodeTrack('base64EncodedTrack');

decodeTracks

decodeTracksmethod

Decode Multiple Tracks

Decodes multiple base64 encoded tracks.

Parameters
encodedTracksrequiredstring[]
Array of base64 encoded tracks

Returns & Example

ReturnsPromise<any>

const tracksInfo = await rest.decodeTracks(['base64Track1', 'base64Track2']);

getPlayers

getPlayersmethod

Get Players

Gets all players in a session.

Parameters
sessionIdrequiredstring
Session ID

Returns & Example

ReturnsPromise<IRESTGetPlayers>

const players = await rest.getPlayers('session-123');

getPlayer

getPlayermethod

Get Player

Gets information about a specific player.

Parameters
sessionIdrequiredstring
Session ID
guildIdrequiredstring
Discord guild ID

Returns & Example

ReturnsPromise<any>

const player = await rest.getPlayer('session-123', '123456789');

getRoutePlannerStatus

getRoutePlannerStatusmethod

Get Route Planner Status

Retrieves the status of the Lavalink Route Planner, which manages IP addresses for outgoing connections.

Returns & Example

ReturnsPromise<any> — Route Planner status object.

const status = await rest.getRoutePlannerStatus();
console.log(status);

unmarkFailedAddress

unmarkFailedAddressmethod

Unmark Failed Address

Unmarks a specific IP address as failed in the Route Planner, allowing it to be used again.

Parameters
addressrequiredstring
The IP address to unmark.

Returns & Example

ReturnsPromise<any>

await rest.unmarkFailedAddress('192.168.1.1');

unmarkAllFailedAddresses

unmarkAllFailedAddressesmethod

Unmark All Failed Addresses

Unmarks all currently failed IP addresses in the Route Planner.

Returns & Example

ReturnsPromise<any>

await rest.unmarkAllFailedAddresses();

patch

patchmethod

Patch Request

Sends a generic PATCH request to a specified path on the Lavalink server.

Parameters
pathrequiredstring
The API path to send the PATCH request to (e.g., sessions/your-session-id).
datarequiredany
The data payload for the PATCH request.

Returns & Example

ReturnsPromise<unknown>

await rest.patch('sessions/my-session-id', { resuming: true });

get

getmethod

Generic GET Request

Sends a generic GET request to a specified path on the Lavalink server.

Parameters
pathrequiredstring
The API path to send the GET request to.

Returns & Example

ReturnsPromise<unknown>

const data = await rest.get('sessions/my-session-id/players');

put

putmethod

Generic PUT Request

Sends a generic PUT request to a specified path on the Lavalink server.

Parameters
pathrequiredstring
The API path to send the PUT request to.
datarequiredany
The data payload for the PUT request.

Returns & Example

ReturnsPromise<unknown>

await rest.put('sessions/my-session-id/player', { volume: 100 });

post

postmethod

Generic POST Request

Sends a generic POST request to a specified path on the Lavalink server.

Parameters
pathrequiredstring
The API path to send the POST request to.
dataany
Optional: The data payload for the POST request.

Returns & Example

ReturnsPromise<unknown>

await rest.post('sessions/my-session-id/player/play', { track: 'encodedTrack' });

delete

deletemethod

Generic DELETE Request

Sends a generic DELETE request to a specified path on the Lavalink server.

Parameters
pathrequiredstring
The API path to send the DELETE request to.

Returns & Example

ReturnsPromise<unknown>

await rest.delete('sessions/my-session-id/player');

Usage Example

Basic Usage

Example of how to use the REST class.

Code Example

// Create a REST instance through a node
const rest = node.rest;

// Load a track
const result = await rest.loadTracks('youtube', 'Never Gonna Give You Up');

// Update a player
await rest.update({
  guildId: '123456789',
  data: {
    track: result.tracks[0].track,
    volume: 100
  }
});

// Get server information
const info = await rest.getInfo();
console.log('Lavalink version:', info.version);

// Decode a track
const trackInfo = await rest.decodeTrack(result.tracks[0].track);
console.log('Track title:', trackInfo.title);
This example demonstrates basic operations using the REST API.