# Vulkava

### Constructor

#### new Vulkava(options)

| Property |     Description     |                                          Type |
| -------- | :-----------------: | --------------------------------------------: |
| options  | The Vulkava options | [VulkavaOptions](/typedefs/vulkavaoptions.md) |

### Properties

| Name     |       Description       |                                                                                                                                                                                                                      Type |
| -------- | :---------------------: | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| nodes    | The lavalink node array |                                                                                                    [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Node](/docs/node.md)> |
| clientId |        The bot id       |                                                                                                                         [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) |
| players  |     The players map     | [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)<[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String), [Player](/docs/player.md)> |

### Methods and events

| Methods                                        |                                                                                                         Events |
| ---------------------------------------------- | -------------------------------------------------------------------------------------------------------------: |
| [addExternalSource](#.addexternalsource)       |                                                                                                    [raw](#raw) |
| [createPlayer](#createplayer)                  |                                                                                    [nodeConnect](#nodeconnect) |
| [decodeTrack](#decodetrack)                    |                                                                                      [nodeResume](#noderesume) |
| [decodeTracks](#decodetracks)                  |                                                                              [nodeDisconnect](#nodedisconnect) |
| [handleVoiceUpdate](#handlevoiceupdate)        |                                                                                                  [warn](#warn) |
| [search](#search)                              |                                                                                                  [pong](#pong) |
| [start](#start)                                |                                                                                                [error](#error) |
| ---                                            | [debug](https://app.gitbook.com/o/31hP1b0naHPzWdBvgu5p/s/pAK5xpA69xJdb8gb28og/~/changes/41/docs/vulkava#debug) |
| ---                                            |                                                                                      [trackStart](#trackstart) |
| ---                                            |                                                                                          [trackEnd](#trackend) |
| ---                                            |                                                                                      [trackStuck](#trackstuck) |
| ---                                            |                                                                              [trackException](#trackexception) |
| ---                                            |                                                                                  [playerCreate](#playercreate) |
| -[-](https://en.wikipedia.org/wiki/Delimiter)- |                                                                                [playerDestroy](#playerdestroy) |
| ---                                            |                                                                          [playerDisconnect](#playerdisconnect) |
| ---                                            |                                                                                          [queueEnd](#queueend) |
| ---                                            |                                                                           [recordFinished](#recordfinished) \* |
| ---                                            |                                                                             [speakingStart](#speakingstart) \* |
| ---                                            |                                                                               [speakingStop](#speakingstop) \* |
| ---                                            |                                                                           [userDisconnect](#userdisconnect) \* |

\* This events only work on [my custom lavalink](https://github.com/davidffa/lavalink/releases), the speakingStart, speakingStop and userDisconnect are only emitted if sendSpeakingEvents is true, in NodeOptions. The speakingStart and speakingStop are only emitted while the lavalink node is recording audio.

### Methods

#### .addExternalSource()

Adds an external source that produces a SearchResult with UnresolvedTracks

<table><thead><tr><th width="211.74086252687493">Parameter</th><th align="right">Description</th></tr></thead><tbody><tr><td>source</td><td align="right">Extends  <a href="https://app.gitbook.com/s/pAK5xpA69xJdb8gb28og/~/changes/NVghI3ljcCnhMB1FLvwc/abstract-classes/abstractexternalsource">AbstractExternalSource</a><br>The external source</td></tr></tbody></table>

#### .createPlayer()

Creates a new player or returns an existing one

<table><thead><tr><th width="211.74086252687493">Parameter</th><th align="right">Description</th></tr></thead><tbody><tr><td>options</td><td align="right"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a><br>The player options</td></tr><tr><td>options.guildId</td><td align="right"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a><br>The guild id that player belongs to</td></tr><tr><td>options.voiceChannelId</td><td align="right"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a><br>The voice channel id</td></tr><tr><td>options.textChannelId</td><td align="right"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a> (optional)<br>The text channel id</td></tr><tr><td>options.selfDeaf</td><td align="right"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a> (optional)<br>Whether the bot joins the voice channel deafened or not</td></tr><tr><td>options.selfMute</td><td align="right"><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean">Boolean</a> (optional)<br>Whether the bot joins the voice channel muted or not</td></tr><tr><td>options.queue</td><td align="right">Extends <a href="https://app.gitbook.com/s/pAK5xpA69xJdb8gb28og/~/changes/NVghI3ljcCnhMB1FLvwc/abstract-classes/abstractqueue">AbstractQueue</a> (optional)<br>A custom queue implementation</td></tr></tbody></table>

| Returns                   | Description |
| ------------------------- | ----------: |
| [Player](/docs/player.md) |  The player |

#### decodeTrack()

Decodes a single base64 encoded track into a [Track](/docs/track.md) instance

| Parameter    |                                                                                                                                     Description |
| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------: |
| encodedTrack | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a><br>The base64 encoded track</p> |

| Returns                                                                                                                      |       Description |
| ---------------------------------------------------------------------------------------------------------------------------- | ----------------: |
| [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Track](/docs/track.md)> | The decoded track |

#### decodeTracks()

Decodes multiple base64 encoded tracks into an array of [Tracks](https://app.gitbook.com/s/pAK5xpA69xJdb8gb28og/docs/track)

| Parameter     |                                                                                                                                                                                                                                                           Description |
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| encodedTracks | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a><<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>><br>The array of base64 encoded tracks</p> |

| Returns                                                                                                                                                                                                                       |        Description |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -----------------: |
| [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Track](/docs/track.md)>> | The decoded tracks |

#### handleVoiceUpdate()

Handles voice state & voice server update packets and pipes them into the lavalink node

This method is meant to be used on the raw event listener of d.js and rawWS (eris) and **requires the gateway intent \`GUILD\_VOICE\_STATES\`** in order to work properly.

| Parameter |                                                                                                                                            Description |
| --------- | -----------------------------------------------------------------------------------------------------------------------------------------------------: |
| payload   | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a><br>The discord gateway raw payload</p> |

#### search()

| Parameter |                                                                                                                                            Description |
| --------- | -----------------------------------------------------------------------------------------------------------------------------------------------------: |
| query     |     <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a><br>The song term to search for</p> |
| source    | <p><a href="/pages/VsRce2Gw4G7r9Zwr92mz">SEARCH\_SOURCE</a> (optional)<br>The source to search if the query is not a valid URL, default is youtube</p> |

| Returns                                                                                                                                        |       Description |
| ---------------------------------------------------------------------------------------------------------------------------------------------- | ----------------: |
| [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[SearchResult](/typedefs/searchresult.md)> | The search result |

#### start()

Starts the Vulkava and connects to all lavalink nodes

| Parameter |                                                                                                                                Description |
| --------- | -----------------------------------------------------------------------------------------------------------------------------------------: |
| clientId  | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a><br>The client (bot) id</p> |

### Events

#### >raw <a href="#raw" id="raw"></a>

Fired when any connected lavalink node emits an event

| Parameter |                                                                                                                               Description |
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------: |
| node      |                                                   <p><a href="/pages/coFH3uUtW2NjOWfwGhn5">Node</a><br>The node this event belongs to</p> |
| payload   | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a><br>The actual payload</p> |

#### > nodeConnect <a href="#nodeconnect" id="nodeconnect"></a>

Fired when a lavalink node connects

| Parameter |                                                                          Description |
| --------- | -----------------------------------------------------------------------------------: |
| node      | <p><a href="/pages/coFH3uUtW2NjOWfwGhn5">Node</a><br>The node that was connected</p> |

#### > nodeResume <a href="#noderesume" id="noderesume"></a>

Fired when a lavalink node resumes its connection (when resumeKey configured)

| Parameter |                                                                        Description |
| --------- | ---------------------------------------------------------------------------------: |
| node      | <p><a href="/pages/coFH3uUtW2NjOWfwGhn5">Node</a><br>The node that was resumed</p> |

#### > nodeDisconnect <a href="#nodedisconnect" id="nodedisconnect"></a>

Fired when a lavalink node disconnects

| Parameter |                                                                                                                                       Description |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------: |
| node      |                                                           <p><a href="/pages/coFH3uUtW2NjOWfwGhn5">Node</a><br>The node that was disconnected</p> |
| code      |   <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a><br>The WebSocket close code</p> |
| reason    | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a><br>The WebSocket close reason</p> |

#### > warn <a href="#warn" id="warn"></a>

Fired when something weird happened

| Parameter |                                                                                                                             Description |
| --------- | --------------------------------------------------------------------------------------------------------------------------------------: |
| node      |                                                                       <p><a href="/pages/coFH3uUtW2NjOWfwGhn5">Node</a><br>The node</p> |
| warn      | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a><br>The warn message</p> |

#### > error <a href="#error" id="error"></a>

Fired when a error occurred

| Parameter |                                                                                                                    Description |
| --------- | -----------------------------------------------------------------------------------------------------------------------------: |
| node      |                                                              <p><a href="/pages/coFH3uUtW2NjOWfwGhn5">Node</a><br>The node</p> |
| error     | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</a><br>The error</p> |

#### > debug <a href="#debug" id="debug"></a>

Event for debug messages

| Parameter |                                                                                                                              Description |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------: |
| message   | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a><br>The debug message</p> |

#### > trackStart <a href="#trackstart" id="trackstart"></a>

Fired when a track starts playing

| Parameter |                                                           Description |
| --------- | --------------------------------------------------------------------: |
| player    | <p><a href="/pages/zFP4cERpMRfV64jFh4u5">Player</a><br>The player</p> |
| track     |   <p><a href="/pages/s670mV6k00OCaJ4zcpQD">Track</a><br>The track</p> |

#### > trackEnd <a href="#trackend" id="trackend"></a>

Fired when a track stops playing

| Parameter |                                                           Description |
| --------- | --------------------------------------------------------------------: |
| player    | <p><a href="/pages/zFP4cERpMRfV64jFh4u5">Player</a><br>The player</p> |
| track     |   <p><a href="/pages/s670mV6k00OCaJ4zcpQD">Track</a><br>The track</p> |
| reason    |     <p>TrackEndReason<br>The reason why the track stopped playing</p> |

{% hint style="info" %}
TrackEndReason = 'FINISHED' | 'LOAD\_FAILED' | 'STOPPED' | 'REPLACED' | 'CLEANUP'
{% endhint %}

#### > trackStuck <a href="#trackstuck" id="trackstuck"></a>

Fired when a track playback stucks

| Parameter   |                                                                                                                                          Description |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------: |
| player      |                                                                                <p><a href="/pages/zFP4cERpMRfV64jFh4u5">Player</a><br>The player</p> |
| track       |                                                                                  <p><a href="/pages/s670mV6k00OCaJ4zcpQD">Track</a><br>The track</p> |
| thresholdMs | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a><br>The threshold in milliseconds</p> |

#### > trackException <a href="#trackexception" id="trackexception"></a>

Fired when a exception occurs during the track playback

| Parameter          |                                                                                                                                       Description |              |                                       |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------: | ------------ | ------------------------------------- |
| player             |                                                                             <p><a href="/pages/zFP4cERpMRfV64jFh4u5">Player</a><br>The player</p> |              |                                       |
| track              |                                                                               <p><a href="/pages/s670mV6k00OCaJ4zcpQD">Track</a><br>The track</p> |              |                                       |
| exception          |       <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object">Object</a><br>The exception object</p> |              |                                       |
| exception.message  |      <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a><br>The exception message</p> |              |                                       |
| exception.severity |                                                                                                                                       <p>'COMMON' | 'SUSPICIOUS' | 'FAULT'<br>The exception severity</p> |
| exception.cause    | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a><br>The cause of the exception</p> |              |                                       |

#### > playerCreate <a href="#playercreate" id="playercreate"></a>

Fired when a player is created

| Parameter |                                                           Description |
| --------- | --------------------------------------------------------------------: |
| player    | <p><a href="/pages/zFP4cERpMRfV64jFh4u5">Player</a><br>The player</p> |

#### > playerDestroy <a href="#playerdestroy" id="playerdestroy"></a>

Fired when a player is destroyed

| Parameter |                                                           Description |
| --------- | --------------------------------------------------------------------: |
| player    | <p><a href="/pages/zFP4cERpMRfV64jFh4u5">Player</a><br>The player</p> |

#### > playerDisconnect <a href="#playerdisconnect" id="playerdisconnect"></a>

Fired when a player gets disconnected from the discord voice server (Vulkava auto-reconnects on close codes: 1006, 4015, 4006 and 4009)

| Parameter |                                                                                                                                                                                                                                                                                       Description |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| player    |                                                                                                                                                                                                                             <p><a href="/pages/zFP4cERpMRfV64jFh4u5">Player</a><br>The player</p> |
| code      | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a><br>The websocket close code<br>See: <a href="https://discord.com/developers/docs/topics/opcodes-and-status-codes#voice-voice-close-event-codes">discord voice close codes</a></p> |
| reason    |                                                                                                                                                 <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a><br>The websocket close reason</p> |

#### > queueEnd <a href="#queueend" id="queueend"></a>

Fired when there is no more tracks to play on the queue

| Parameter |                                                           Description |
| --------- | --------------------------------------------------------------------: |
| player    | <p><a href="/pages/zFP4cERpMRfV64jFh4u5">Player</a><br>The player</p> |

#### > pong <a href="#pong" id="pong"></a>

Fired when a lavalink node emits a pong event (used to get lavalink latency)

| Parameter |                                                                                                                                                                              Description |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| node      |                                                                                                                        <p><a href="/pages/coFH3uUtW2NjOWfwGhn5">Node</a><br>The node</p> |
| ping      | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">Number</a> (optional)<br>The latency between a player and discord voice gateway</p> |

#### > recordFinished <a href="#recordfinished" id="recordfinished"></a>

Fired when a lavalink node has finished processing an audio recording

| Parameter |                                                                                                                          Description |
| --------- | -----------------------------------------------------------------------------------------------------------------------------------: |
| node      |                                              <p><a href="/pages/coFH3uUtW2NjOWfwGhn5">Node</a><br>The node that fired this event</p> |
| guildId   |   <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a><br>The guildId</p> |
| id        | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a><br>The record id</p> |

#### > speakingStart <a href="#speakingstart" id="speakingstart"></a>

Fired when a user started speaking (only works while recording and if sendSpeakingEvents=true in NodeOptions)

| Parameter |                                                                                                                        Description |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------: |
| player    |                                                              <p><a href="/pages/zFP4cERpMRfV64jFh4u5">Player</a><br>The player</p> |
| userId    | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a><br>The user id</p> |

#### > speakingStop <a href="#speakingstop" id="speakingstop"></a>

Fired when a user stopped speaking (100ms of silence) (only works while recording and if sendSpeakingEvents=true in NodeOptions)

| Parameter |                                                                                                                        Description |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------: |
| player    |                                                              <p><a href="/pages/zFP4cERpMRfV64jFh4u5">Player</a><br>The player</p> |
| userId    | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a><br>The user id</p> |

#### > userDisconnect <a href="#userdisconnect" id="userdisconnect"></a>

Fired when a user disconnected from the voice channel (only works if sendSpeakingEvents=true in NodeOptions)

| Parameter |                                                                                                                        Description |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------: |
| player    |                                                              <p><a href="/pages/zFP4cERpMRfV64jFh4u5">Player</a><br>The player</p> |
| userId    | <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String">String</a><br>The user id</p> |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://vulkava.js.org/docs/vulkava.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
