export declare class VoiceConnection extends EventEmitter
export declare class VoiceConnection extends EventEmitter
A connection to the voice server of a Guild, can be used to play audio in voice channels.
Extends
EventEmitterconstructor(joinConfig, options)
Creates a new voice connection.
Name | Type | Optional | Description |
---|---|---|---|
joinConfig | JoinConfig | No | The data required to establish the voice connection |
options | CreateVoiceConnectionOptions | No | The options used to create this voice connection |
Readonly
ping
:
{ ws: number | undefined; udp: number | undefined; }
The latest ping (in milliseconds) for the WebSocket connection and audio playback for this voice connection, if this data is available.
Remarks
For this data to be available, the VoiceConnection must be in the Ready state, and its underlying WebSocket connection and UDP socket must have had at least one ping-pong exchange.Readonly
The receiver of this voice connection. You should join the voice channel with
selfDeaf
set to false for this feature to work properly.rejoinAttempts
:
number
The number of consecutive rejoin attempts. Initially 0, and increments for each rejoin. When a connection is successfully established, it resets to 0.
The current state of the voice connection.
configureNetworking()
:
void
Attempts to configure a networking instance for this voice connection using the received packets. Both packets are required, and any existing networking instance will be destroyed.
Remarks
This is called when the voice server of the connection changes, e.g. if the bot is moved into a different channel in the same guild but has a different voice server. In this instance, the connection needs to be re-established to the new voice server.The connection will transition to the Connecting state when this is called.destroy(adapterAvailable?)
:
void
Destroys the VoiceConnection, preventing it from connecting to voice again. This method should be called when you no longer require the VoiceConnection to prevent memory leaks.
Name | Type | Optional | Description |
---|---|---|---|
adapterAvailable | boolean | Yes | Whether the adapter can be used |
disconnect()
:
boolean
Disconnects the VoiceConnection, allowing the possibility of rejoining later on.
dispatchAudio()
:
boolean | undefined
Dispatches the previously prepared audio packet (if any)
Protected
onSubscriptionRemoved(subscription)
:
void
Called when a subscription of this voice connection to an audio player is removed.
Name | Type | Optional | Description |
---|---|---|---|
subscription | PlayerSubscription | No | The removed subscription |
playOpusPacket(buffer)
:
boolean | undefined
Prepares an audio packet and dispatches it immediately.
Name | Type | Optional | Description |
---|---|---|---|
buffer | Buffer | No | The Opus packet to play |
prepareAudioPacket(buffer)
:
Buffer | undefined
Prepares an audio packet for dispatch.
Name | Type | Optional | Description |
---|---|---|---|
buffer | Buffer | No | The Opus packet to prepare |
rejoin(joinConfig?)
:
boolean
Attempts to rejoin (better explanation soon:tm:)
Remarks
Calling this method successfully will automatically increment therejoinAttempts
counter, which you can use to inform whether or not you'd like to keep attempting to reconnect your voice connection.A state transition from Disconnected to Signalling will be observed when this is called.Name | Type | Optional | Description |
---|---|---|---|
joinConfig | Omit<JoinConfig, 'group' | 'guildId'> | Yes | None |
setSpeaking(enabled)
:
false | void
Updates the speaking status of the voice connection. This is used when audio players are done playing audio, and need to signal that the connection is no longer playing audio.
Name | Type | Optional | Description |
---|---|---|---|
enabled | boolean | No | Whether or not to show as speaking |
Subscribes to an audio player, allowing the player to play audio on this voice connection.
Name | Type | Optional | Description |
---|---|---|---|
player | AudioPlayer | No | The audio player to subscribe to |
on(event, listener)
:
this
Emitted when there is an error emitted from the voice connection
Name | Type | Optional | Description |
---|---|---|---|
event | 'error' | No | None |
listener | (error: Error) => void | No | None |