Class

VoiceConnection

Voice connection using Discord's UDP-based protocol. Emits `ready`, `error`, `disconnect`.

Extends EventEmitter

Constructor

new VoiceConnection(client: Client, channel: VoiceChannel, userId: string)
ParamTypeDescription
clientClient
channelVoiceChannel
userIdstring

Properties

audioPacketQueue: Buffer[]
channel: VoiceChannel (readonly)
client: Client (readonly)
currentStream: { destroy?: () => void } | null
guildId: string (readonly)
heartbeatInterval: ReturnType<typeof setInterval> | null
pacingInterval: ReturnType<typeof setInterval> | null
playing: boolean (readonly)

Whether audio is currently playing.

remoteUdpAddress: string
remoteUdpPort: number
secretKey: Uint8Array | null
sequence: number
sessionId: string | null (readonly)

Discord voice session ID.

ssrc: number
timestamp: number
udpSocket: dgram.Socket | null
voiceWs: VoiceWebSocket | null

Methods

Called when we have both server update and state update.

destroy(): void

Disconnect and remove all listeners.

disconnect(): void

Disconnect from voice (closes WebSocket and UDP).

getWebSocketConstructor(): Promise<new (url: string) => VoiceWebSocket>
play(urlOrStream: string | NodeJS.ReadableStream): Promise<void>

Play a direct WebM/Opus source. When `urlOrStream` is a string: - `http://` / `https://` — fetched over the network - `file://` — read from the local filesystem - any other string — treated as a filesystem path (e.g. `./music/track.webm`) You can also pass a Node.js Readable stream. Demuxes with prism-media WebmDemuxer; no FFmpeg; input must be WebM with Opus.

ParamTypeDescription
urlOrStreamstring | NodeJS.ReadableStream
playOpus(stream: NodeJS.ReadableStream): void

Play a stream of raw Opus packets Uses the same queue and 20ms pacing as play(). Use this for raw Opus packet streams (e.g. MP3 → PCM → Opus pipelines) when you are not using WebM/Opus.

ParamTypeDescription
streamNodeJS.ReadableStream
sendAudioFrame(opusPayload: Buffer): void
ParamTypeDescription
opusPayloadBuffer
sendVoiceOp(op: number, d: unknown): void
ParamTypeDescription
opnumber
dunknown
setupUDP(remoteAddress: string, remotePort: number, onReady: () => void): void
ParamTypeDescription
remoteAddressstring
remotePortnumber
onReady() => void
stop(): void

Stop playback and clear the queue.