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

Cannot record users in VC when they are using Discord in their browser. #5640

Closed
nicnacnic opened this issue May 17, 2021 · 4 comments
Closed
Assignees

Comments

@nicnacnic
Copy link

Please describe the problem you are having in as much detail as possible:
I'm using Discord.JS to capture audio from a voice channel. While it works quite well on desktop/mobile, it crashes when using Discord from a browser. I'm using opusscript as my Opus library, but the same thing should happen if using @discord.js/opus (untested). My guess is that Discord encodes audio differently when using a browser.

Error:

Error: Decode error: Invalid packet
    at OpusScript.decode (C:\Users\Nicolas\node_modules\opusscript\index.js:82:15)
    at Decoder._decode (C:\Users\Nicolas\Documents\Marathons\Audio Capture Bot\node_modules\prism-media\src\opus\Opus.js:64:25)
    at Decoder._transform (C:\Users\Nicolas\Documents\Marathons\Audio Capture Bot\node_modules\prism-media\src\opus\Opus.js:204:22)
    at Decoder.Transform._write (node:internal/streams/transform:184:23)
    at writeOrBuffer (node:internal/streams/writable:395:12)
    at Decoder.Writable.write (node:internal/streams/writable:340:10)
    at Readable.ondata (node:internal/streams/readable:750:22)
    at Readable.emit (node:events:369:20)
    at addChunk (node:internal/streams/readable:313:12)
    at readableAddChunk (node:internal/streams/readable:288:9)
Emitted 'error' event on Decoder instance at:
    at Decoder.onerror (node:internal/streams/readable:769:14)
    at Decoder.emit (node:events:369:20)
    at emitErrorNT (node:internal/streams/destroy:188:8)
    at emitErrorCloseNT (node:internal/streams/destroy:153:3)
    at processTicksAndRejections (node:internal/process/task_queues:81:21)

Include a reproducible code sample here, if possible:
This sample uses node-speaker to play the output. This issue can also be tested with the full bot, DACBot.

async function record(message) {
let connection = await message.member.voice.channel.join();
const voiceConnection = connection.receiver.createStream(message.author.id, { mode: 'pcm', end: 'manual' });
const speaker = new Speaker({
	channels: 2,
	bitDepth: 16,
	sampleRate: 48000
});
voiceConnection.pipe(speaker);
}

Further details:

  • discord.js version: 12.5.3
  • Node.js version: 15.14.0
  • Operating system: Windows 10
  • Priority this issue should have – please be realistic and elaborate if possible: Medium. While most people don't really use Discord.JS to record users, this is a bot-breaking bug for anyone who does use it to record users.

Relevant client options:

  • partials: none
  • gateway intents: none
  • other: none
@amishshah
Copy link
Member

Can you reproduce this using the master branch of the library? A fix for receiving audio from browser clients was merged a few weeks ago

@sasial-dev
Copy link

To install the master branch, you can change your package.json version to:

"discord.js":  "discordjs/discord.js"

@nicnacnic
Copy link
Author

Nope, it's not working. Same error. I'm using the Stable 85039 (a2070b8) version of Discord both on desktop and browser.

@amishshah amishshah self-assigned this May 26, 2021
@amishshah
Copy link
Member

Hi there,

We're working on a new implementation of Discord's Voice API that has better playback quality and is more reliable than what we currently support in Discord.js v12 - check it out at https://github.com/discordjs/voice!

The new library solves many of the issues that users are facing, and as part of this, we're dropping built-in support for voice in our next major release. We have a PR (#5402) that adds native support for our new voice library - once this PR is merged, this issue will be closed.

You can still use our new voice library before that PR lands - just take a look at our music bot example to see how to get started upgrading your voice code. By using the boilerplate music player in the example, you can make it even easier to upgrade your code.

Note that the PR above only reduces some of the boilerplate code you'd otherwise have to write - you do not have to wait for the PR to be merged to start using the new voice library.


If you have any questions about this, feel free to:

  • Make an issue if you have found a bug in the new voice library
  • Use GitHub Discussions or join our Discord server (we have a new channel, #djs-new-voice, specifically for this!) to ask general questions about the library, give feedback on the library, and get support with upgrading to it

Specific to this issue:

This event relies on the voice receive feature, which is undocumented by Discord and prone to breaking quite a lot. As it's an undocumented feature, we cannot guarantee support for it. The new voice library will still have support for voice receive, but even then it will not be a stable feature.

@kyranet kyranet closed this as completed Jun 9, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants