Manager
The core class responsible for managing nodes, players, and audio search.
Constructor Options
| Option | Type | Required | Description |
|---|---|---|---|
nodes | array | Required | Array of Lavalink node configurations. |
send | function | Required | Function to send voice data to Discord. |
autoPlay | boolean | Optional | Automatically play the next track in queue. |
autoResume | boolean | Optional | Resume playback after node reconnects. |
autoMove | boolean | Optional | Move players to another node if node disconnects. |
shards | number | Optional | Number of shards the bot is using. |
defaultSearchPlatform | string | Optional | Default search platform (e.g. 'youtube music'). |
trackPartial | string[] | Optional | Array of track properties to keep after resolving. |
clientId | string | Optional | Discord client ID. |
clientName | string | Optional | Discord client name. |
plugins | array | Optional | Array of plugins to load. |
Properties
nodesThe map of all connected nodes.
playersThe map of all active players.
optionsThe options passed to the constructor.
Methods
init(clientId)→ thisInitiates the Manager and connects to all configured nodes. Must be called once your Discord client is ready.
| Parameter | Type | Required |
|---|---|---|
clientId | string | Required |
search(query, requester)→ Promise<SearchResult>Searches the enabled sources based on the URL or search query. Supports YouTube, SoundCloud, Spotify, and more.
| Parameter | Type | Required |
|---|---|---|
query | string | SearchQuery | Required |
requester | unknown | Optional |
create(options)→ PlayerCreates a new player or returns an existing one for the specified guild.
| Parameter | Type | Required |
|---|---|---|
options | PlayerOptions | Required |
get(guildId)→ Player | undefinedReturns a player for the specified guild, or undefined if it doesn't exist.
| Parameter | Type | Required |
|---|---|---|
guildId | string | Required |
destroy(guildId)→ voidDestroys a player if it exists.
| Parameter | Type | Required |
|---|---|---|
guildId | string | Required |
createNode(options)→ NodeCreates a node or returns one if it already exists.
| Parameter | Type | Required |
|---|---|---|
options | NodeOptions | Required |
destroyNode(identifier)→ voidDestroys a node if it exists.
| Parameter | Type | Required |
|---|---|---|
identifier | string | Required |
decodeTrack(track)→ Promise<TrackData>Decodes a base64 encoded track string and returns TrackData.
| Parameter | Type | Required |
|---|---|---|
track | string | Required |
decodeTracks(tracks)→ Promise<TrackData[]>Decodes multiple base64 encoded track strings and returns a TrackData array.
| Parameter | Type | Required |
|---|---|---|
tracks | string[] | Required |
updateVoiceState(data)→ voidSends voice state data to the Lavalink server. This must be called on every raw Discord event.
| Parameter | Type | Required |
|---|---|---|
data | VoicePacket | Required |
Events
Listen to Manager events using manager.on(event, callback)
nodeCreateNodeEmitted when a Node is created.
nodeDestroyNodeEmitted when a Node is destroyed.
nodeConnectNodeEmitted when a Node connects.
nodeReconnectNodeEmitted when a Node reconnects.
nodeDisconnectNode{ code, reason }Emitted when a Node disconnects.
nodeErrorNodeErrorEmitted when a Node has an error.
playerCreatePlayerEmitted when a Player is created.
playerDestroyPlayerEmitted when a Player is destroyed.
playerMovePlayeroldChannelnewChannelEmitted when a Player moves to a new voice channel.
queueEndPlayerEmitted when the player's queue ends.
trackStartPlayerTrackTrackStartEventEmitted when a track starts playing.
trackEndPlayerTrackTrackEndEventEmitted when a track ends.
trackStuckPlayerTrackTrackStuckEventEmitted when a track gets stuck during playback.
trackErrorPlayerTrackTrackExceptionEventEmitted when a track has a playback error.
socketClosedPlayerWebSocketClosedEventEmitted when a voice WebSocket connection closes.
nodeRawpayloadEmitted whenever any Lavalink event is received.