Please describe the problem you are having in as much detail as possible:
When creating a readable stream for audio, no audio is received from the on data event. This used to work a month or so ago, but no longer works. No data is passed, the on end event is never passed.
Include a reproducible code sample here, if possible:
const audioStream = voiceReceiver.createStream(member, { end: 'manual', mode: 'pcm' });
audioStream.on('data', (chunk) => {
console.log(`Received ${chunk.length} bytes of data.`);
});
Further details:
Discord used to have a bug where bots couldn't receive audio if they didn't play any audio, it got fixed but I just tested now and it looks like it came back. There have been reports of this from users of other libraries, so my suggestion would be to consider playing a silent audio file when your bot joins a channel so that it can still receive audio until Discord fixes it.
That worked. Thank you very much for the temporary fix.
No problem! I'll keep this open until a Discord dev can give us more info.
This issue is also reproduced in JDA https://github.com/DV8FromTheWorld/JDA/issues/789
So, I tried this
client.on('message', msg => {
if (msg.content.startsWith(config.prefix)) {
let [command, ...channelName] = msg.content.split(" ");
const voiceChannel = msg.guild.channels.find("name", channelName.join(" "));
if (!voiceChannel || voiceChannel.type !== 'voice') {
return;
}
voiceChannel.join().then((voiceConnection) => {
const dispatcher = voiceConnection.playFile('./beep.mp3');
const receiver = voiceConnection.createReceiver();
voiceConnection.on("speaking",
(user, speaking) => {
if (speaking) {
# Only crashes on this line
const audioStream = receiver.createStream(user);
audioStream.on('data',
(chunk) => {
console.log(`Received ${chunk.length} bytes of data.`);
});
}
});
});
}
if (msg.content.startsWith(config.prefix + 'leave')) {
let [command, ...channelName] = msg.content.split(" ");
let voiceChannel = msg.guild.channels.find("name", channelName.join(" "));
voiceChannel.leave();
}
});
where beep.mp3 is a 1 1/2h of silence lol.
The line that crashes me is marked with a comment.
It gives me no description tho..
+1
Bot listen me, when playing sound. But i have one more problem:
Received 3840 bytes of data.
Received 3840 bytes of data.
Received 3840 bytes of data.
Received 3840 bytes of data.
Received 3840 bytes of data.
Received 3840 bytes of data.
Received 3840 bytes of data.
Received 3840 bytes of data.
Received 3840 bytes of data.
Received 3840 bytes of data.
Received 3840 bytes of data.
Received 3840 bytes of data.
Received 3840 bytes of data.
Received 3840 bytes of data.
Received 3840 bytes of data.
Received 3840 bytes of data.
Received 3840 bytes of data.
Received 3840 bytes of data.
Received 3840 bytes of data.
Received 3840 bytes of data.
Received 3840 bytes of data.
Received 3840 bytes of data.
Received 3840 bytes of data.
abort() at Error
at jsStackTrace (C:\Denwer\ddradio\node_modules\opusscript\build\opusscript_
native.js:1:15907)
at stackTrace (C:\Denwer\ddradio\node_modules\opusscript\build\opusscript_na
tive.js:1:16090)
at Object.abort (C:\Denwer\ddradio\node_modules\opusscript\build\opusscript_
native.js:17:4652)
at _abort (C:\Denwer\ddradio\node_modules\opusscript\build\opusscript_native
.js:1:156423)
at Me (C:\Denwer\ddradio\node_modules\opusscript\build\opusscript_native.js:
10:14106)
at Array.Fc (C:\Denwer\ddradio\node_modules\opusscript\build\opusscript_nati
ve.js:7:1316)
at Array.Nc (C:\Denwer\ddradio\node_modules\opusscript\build\opusscript_nati
ve.js:7:8378)
at Kf (C:\Denwer\ddradio\node_modules\opusscript\build\opusscript_native.js:
10:31011)
at dynCall_vii_1 (eval at makeDynCaller (C:\Denwer\ddradio\node_modules\opus
script\build\opusscript_native.js:1:171987), <anonymous>:4:12)
at Function.OpusScriptHandler$destroy_handler [as destroy_handler] (eval at
new_ (C:\Denwer\ddradio\node_modules\opusscript\build\opusscript_native.js:1:179
928), <anonymous>:8:1)
If this abort() is unexpected, build with -s ASSERTIONS=1 which can give more in
formation.
and stopping. Can you help me with it, please?
Minn from JDA:

I've been trying Minn's fix but it doesn't seem to be working :/
Putting this here for completeness
https://github.com/Discord4J/Discord4J/issues/452
See https://github.com/discordapp/discord-api-docs/issues/808#issuecomment-457962359, I'll try the workarounds mentioned by Minn and see if they fix the issue
Temporary workaround until Discord acknowledges and fixes the issue:
const { Readable } = require('stream');
const SILENCE_FRAME = Buffer.from([0xF8, 0xFF, 0xFE]);
class Silence extends Readable {
_read() {
this.push(SILENCE_FRAME);
}
}
// play silence indefinitely, this should allow you to continue receiving audio
voiceConnection.play(new Silence(), { type: 'opus' });
As per https://github.com/discordapp/discord-api-docs/issues/808 (see below), it seems that Discord does not support receiving audio and there currently seems to be no immediate intention of supporting it.

I'd hate to entirely remove this feature from Discord.js because it _can_ work with some tinkering around. However, without any documentation or communication from the developers I'm no longer going to actively maintain this feature as it's too unstable.
Sorry for how this has turned out! 😢 I'll leave this issue open to continue posting any updates about the situation and hopefully we'll be able to resolve this once documentation is provided.
Sending the silence frame only once also works for me:
const { Readable } = require('stream');
const SILENCE_FRAME = Buffer.from([0xF8, 0xFF, 0xFE]);
class Silence extends Readable {
_read() {
this.push(SILENCE_FRAME);
this.destroy();
}
}
voiceConnection.play(new Silence(), { type: 'opus' });
Does the commit above work for you?
This bug is breakin' my b**
Most helpful comment
Sending the silence frame only once also works for me: