Discord Player

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.

new VoiceConnection(joinConfig, options);
ParameterTypeOptionalDescription
joinConfigJoinConfigThe data required to establish the voice connection
optionsCreateVoiceConnectionOptionsThe 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.

ParameterTypeOptionalDescription
adapterAvailablebooleanWhether 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

ParameterTypeOptional
event'error'
listener( error: Error ) => void

public onSubscriptionRemoved(subscription): void

Called when a subscription of this voice connection to an audio player is removed.

ParameterTypeOptionalDescription
subscriptionPlayerSubscriptionThe removed subscription

public playOpusPacket(buffer): undefined | boolean

Prepares an audio packet and dispatches it immediately.

ParameterTypeOptionalDescription
bufferBufferThe Opus packet to play

public prepareAudioPacket(buffer): undefined | Buffer

Prepares an audio packet for dispatch.

ParameterTypeOptionalDescription
bufferBufferThe Opus packet to prepare

public rejoin(joinConfig?): boolean

Attempts to rejoin (better explanation soon:tm:)

ParameterTypeOptional
joinConfigOmit<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.

ParameterTypeOptionalDescription
enabledbooleanWhether 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.

ParameterTypeOptionalDescription
playerAudioPlayerThe audio player to subscribe to