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.

Constructors

constructor()

Creates a new 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.

readonly
receiver : VoiceReceiver

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.

destroy(
adapterAvailable?: boolean
) : 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.

disconnect() : boolean

Disconnects the VoiceConnection, allowing the possibility of rejoining later on.

Returns: true if the connection was successfully disconnected

dispatchAudio() : boolean | undefined

Dispatches the previously prepared audio packet (if any)

protected
onSubscriptionRemoved(
subscription: PlayerSubscription
) : void

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

playOpusPacket(
buffer: Buffer
) : boolean | undefined

Prepares an audio packet and dispatches it immediately.

prepareAudioPacket(
buffer: Buffer
) : Buffer | undefined

Prepares an audio packet for dispatch.

rejoin(
joinConfig?: Omit<JoinConfig, 'group' | 'guildId'>
) : boolean

Attempts to rejoin (better explanation soon:tm:)

setSpeaking(
enabled: boolean
) : 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.

subscribe(
player: AudioPlayer
) : PlayerSubscription | undefined

Subscribes to an audio player, allowing the player to play audio on this voice connection.

Returns: The created subscription

on(
event: 'error'
listener: (error: Error) => void
) : this

Emitted when there is an error emitted from the voice connection