Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discord does not support receiving audio #2929

Closed
1 of 2 tasks
iDerp opened this issue Nov 4, 2018 · 17 comments
Closed
1 of 2 tasks

Discord does not support receiving audio #2929

iDerp opened this issue Nov 4, 2018 · 17 comments
Assignees

Comments

@iDerp
Copy link

@iDerp iDerp commented Nov 4, 2018

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.js version: 12.0.0-dev (master)
  • Node.js version: v8.11.4
  • Operating system: Windows 10 (also tested on Ubuntu 16.04 with node v11.0.0)
  • Priority this issue should have – please be realistic and elaborate if possible:
    High priority for bots needing audio receiving
  • I found this issue while running code on a user account
  • I have also tested the issue on latest master, commit hash: f3cad81
@amishshah amishshah self-assigned this Nov 4, 2018
@amishshah
Copy link
Member

@amishshah amishshah commented Nov 4, 2018

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.

@iDerp
Copy link
Author

@iDerp iDerp commented Nov 4, 2018

That worked. Thank you very much for the temporary fix.

@amishshah
Copy link
Member

@amishshah amishshah commented Nov 4, 2018

No problem! I'll keep this open until a Discord dev can give us more info.

@amishshah
Copy link
Member

@amishshah amishshah commented Nov 6, 2018

This issue is also reproduced in JDA DV8FromTheWorld/JDA#789

@Logxn
Copy link

@Logxn Logxn commented Nov 11, 2018

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

@IcedElect

This comment has been minimized.

@IcedElect
Copy link

@IcedElect IcedElect commented Nov 23, 2018

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?

@BenjaminUrquhart
Copy link

@BenjaminUrquhart BenjaminUrquhart commented Jan 14, 2019

Minn from JDA:
discordcanary_2019-01-14_09-16-40

@amishshah
Copy link
Member

@amishshah amishshah commented Jan 14, 2019

I've been trying Minn's fix but it doesn't seem to be working :/

@BenjaminUrquhart
Copy link

@BenjaminUrquhart BenjaminUrquhart commented Jan 17, 2019

Putting this here for completeness
Discord4J/Discord4J#452

@amishshah
Copy link
Member

@amishshah amishshah commented Jan 27, 2019

See discord/discord-api-docs#808 (comment), I'll try the workarounds mentioned by Minn and see if they fix the issue

@amishshah
Copy link
Member

@amishshah amishshah commented Jan 29, 2019

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' });

@amishshah amishshah changed the title voiceReceiver/createStream no longer receiving data Discord does not support receiving audio Jan 30, 2019
@amishshah
Copy link
Member

@amishshah amishshah commented Jan 30, 2019

As per discord/discord-api-docs#808 (see below), it seems that Discord does not support receiving audio and there currently seems to be no immediate intention of supporting it.

image

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.

@Schabimperle
Copy link

@Schabimperle Schabimperle commented Feb 3, 2019

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' });

@kyranet
Copy link
Member

@kyranet kyranet commented Feb 9, 2019

Does the commit above work for you?

@egeste

This comment has been minimized.

@iCrawl
Copy link
Member

@iCrawl iCrawl commented Feb 24, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants