LavalinkManager

The main Base-Manager of this Package

Type: class extends node:EventEmitter

Constructor

new LavalinkManager(options:ManagerOptions)

Import

index.ts
import { LavalinkManager } from "lavalink-client";

Overview

Check out Example Creations down below


Properties

.initated

If the Manager was initated

Type: Boolean

.useable

If the Manager is useable (If at least 1 Node is connected)

Type: Boolean

.options

The options from the Manager

Type: ManagerOptions

.players

All the Players of the Manager

Type: MiniMap<guildId:string, Player>

.nodeManager

The Node Manager of the Manager

Type: NodeManager

.utils

The Manager's Utils

Type: ManagerUtils


Methods

.init(clientData: BotClientOptions) IMPORTANT!

Initializes the Manager and connects all Nodes

Returns: Promise<LavalinkManager>

.createPlayer(options: PlayerOptions)

Create or get a Player

Returns: Player

.getPlayer(guildId:string)

Create a Player

Returns: Player | undefined

Important Conditions to check:

  • player is not undefined

  • player is connected to a VoiceChannel

  • user in a VoiceChannel && player in same VoiceChannel as user

  • player.node is Connected

  • player is playing / there is a current song in player.queue

.deletePlayer(guildId:string)

Removes a Player from the saved MiniMap, needs to be destroyed first

Returns: Boolean

.sendRawData(data : VoicePacket | VoiceServer | VoiceState | any) IMPORTANT!

Sends Raw Discord's Clients Event Data to the Manager

Returns: void


Event-Listeners

All Events you can listen to on the LavalinkManager Class

trackStart

Emitted whenever a Track plays

Parameter
Type
Description

player

The Player for this Event

track

The current playing track (player.queue.current)

payload

The Payload Lavalink sent

trackEnd

Emitted whenever a Track finished playing.

Parameter
Type
Description

player

The Player for this Event

track

The Track that finished Playing

payload

The Payload Lavalink sent

trackStuck

Emitted whenever a Track got stuck while playing

Parameter
Type
Description

player

The Player for this Event

track

The Track that got stuck

payload

The Payload Lavalink sent

trackError

Emitted whenever a Track errored

Parameter
Type
Description

player

The Player for this Event

track

The Track that Errored

payload

The Payload Lavalink sent

queueEnd

Emitted when the track Ended, but there are no more tracks in the queue

(trackEnd, does NOT get exexcuted)

Parameter
Type
Description

player

The Player for this Event

track

The last played track

payload

The Payload Lavalink sent

playerCreate

Emitted whenver a Player gets created

Parameter
Type
Description

player

The created Player

playerMove

Emitted whenever a Player gets moved between Voice Channels

Parameter
Type
Description

player

The Player for this Event

oldVoiceChannelId

old Voice Channel Id

newVoiceChannelId

new Voice Channel Id

playerDisconnect

Emitted whenever a player is disconnected from a channel

Parameter
Type
Description

player

The Player for this Event

voiceChannelId

The disconnected voice Channel

playerSocketClose

Emitted when a Node-Socket got closed for a specific Player

Parameter
Type
Description

player

The Player for this Event

payload

The Payload Lavalink sent

playerDestroy

Emitted whenever a Player got destroyed

Parameter
Type
Description

player

The Destroyed Player

destroyReason

The Destroy Reason (if provided)

playerUpdate

Emitted whenever a Player gets an update from Lavalink's playerUpdate Event

Parameter
Type
Description

oldPlayerJson

Player Data before it was udpated

newPlayer

Afterwards the Player got updated

Example-Creations

Example Creation

Finally, initatlize the Manager and send Raw Data!

Advanced Example Creation

Example with Redis-Queue, Request-Transformer, Autoplay Function, ...

Custom Queue Store Class (Saving the queue on a redis server)

Custom Queue Changes Watcher Class, for seeing changes within the Queue

Custom Autoplay function, which gets executed, before the "queueEnd" Event fires, and if there is a new track added in the queue, then it plays it. else "queueEnd" will fire

Custom requestTransformer Function, which allows you to provide just a User Object into the "requester" parameter(s) and then transform it to save memory! Attention: This function might get executed on already transformed requesters, if you re-use it.

Finally, initatlize the Manager and send Raw Data!

Last updated