VoiceConnection
A connection to the voice server of a Guild, can be used to play audio in voice channels.
VoiceConnection extends EventEmitter
A connection to the voice server of a Guild, can be used to play audio in voice channels.
Parameter | Type | Optional | Description |
---|---|---|---|
joinConfig | JoinConfig | ❌ | The data required to establish the voice connection |
options | CreateVoiceConnectionOptions | ❌ | The options used to create this voice connection |
Properties
public joinConfig: any
A configuration storing all the data needed to reconnect to a Guild's voice server.
public rejoinAttempts: any
The number of consecutive rejoin attempts. Initially 0, and increments for each rejoin. When a connection is successfully established, it resets to 0.
public ping: any
The latest ping (in milliseconds) for the WebSocket connection and audio playback for this voice connection, if this data is available.
public state: any
The current state of the voice connection.
Methods
public 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.
public 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.
Parameter | Type | Optional | Description |
---|---|---|---|
adapterAvailable | boolean | ❌ | Whether the adapter can be used |
public disconnect(): boolean
Disconnects the VoiceConnection, allowing the possibility of rejoining later on.
public dispatchAudio(): undefined | boolean
Dispatches the previously prepared audio packet (if any)
public on(event, listener): this
Emitted when there is an error emitted from the voice connection
public onSubscriptionRemoved(subscription): void
Called when a subscription of this voice connection to an audio player is removed.
Parameter | Type | Optional | Description |
---|---|---|---|
subscription | PlayerSubscription | ❌ | The removed subscription |
public playOpusPacket(buffer): undefined | boolean
Prepares an audio packet and dispatches it immediately.
Parameter | Type | Optional | Description |
---|---|---|---|
buffer | Buffer | ❌ | The Opus packet to play |
public prepareAudioPacket(buffer): undefined | Buffer
Prepares an audio packet for dispatch.
Parameter | Type | Optional | Description |
---|---|---|---|
buffer | Buffer | ❌ | The Opus packet to prepare |
public rejoin(joinConfig?): boolean
Attempts to rejoin (better explanation soon:tm:)
Parameter | Type | Optional |
---|---|---|
joinConfig | Omit<JoinConfig'group''guildId'> | ✅ |
public 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.
Parameter | Type | Optional | Description |
---|---|---|---|
enabled | boolean | ❌ | Whether or not to show as speaking |
public subscribe(player): undefined | PlayerSubscription
Subscribes to an audio player, allowing the player to play audio on this voice connection.
Parameter | Type | Optional | Description |
---|---|---|---|
player | AudioPlayer | ❌ | The audio player to subscribe to |