Discord Voice Lags Progressively

I’m using the latest discord.js and @discordjs/voice libraries, and I’m seeing a reproducible delay issue: when the bot plays a sound, Discord instantly shows the green speaking ring, but the audible audio arrives noticeably later (hundreds of milliseconds). The strange part is that this delay only happens when the bot stays connected; if I destroy the voice connection and rejoin the channel before each play, the delay completely disappears. I’ve tested with pre-encoded Ogg/Opus files (no FFmpeg at play time), a single AudioPlayer, different regions, and multiple listening clients. The bot triggers playback instantly, but with a long-lived voice connection the audio seems buffered or delayed, while a fresh connection plays immediately as expected. This makes it look like something in the voice pipeline accumulates delay over time. Is this a known issue, or is there a way to reset the audio/jitter buffer without reconnecting on every play?
async playSound(channel: VoiceBasedChannel, sound: SoundEnum) {
const t0 = performance.now();

this.playCount++;

const conn = this.ensureConnection(channel);

this.player.stop();

const filepath = filePathService.getSoundPath(sound);

const stream = createReadStream(filepath, { highWaterMark: SoundServiceClass.STREAM_BUFFER_SIZE });
const resource = createAudioResource(stream, {
inputType: StreamType.OggOpus,
inlineVolume: false,
});

this.player.play(resource);

conn.subscribe(this.player);

const prepMs = Math.round((performance.now() - t0) * 1000) / 1000;
console.log(`${sound} → #${channel.name} (prep ${prepMs} ms) [Opus Stream] [Play #${this.playCount}]`);
async playSound(channel: VoiceBasedChannel, sound: SoundEnum) {
const t0 = performance.now();

this.playCount++;

const conn = this.ensureConnection(channel);

this.player.stop();

const filepath = filePathService.getSoundPath(sound);

const stream = createReadStream(filepath, { highWaterMark: SoundServiceClass.STREAM_BUFFER_SIZE });
const resource = createAudioResource(stream, {
inputType: StreamType.OggOpus,
inlineVolume: false,
});

this.player.play(resource);

conn.subscribe(this.player);

const prepMs = Math.round((performance.now() - t0) * 1000) / 1000;
console.log(`${sound} → #${channel.name} (prep ${prepMs} ms) [Opus Stream] [Play #${this.playCount}]`);
1 Reply
d.js toolkit
d.js toolkit2w ago

Did you find this page helpful?