question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sending and receiving audio within the same connection does not work

See original GitHub issue

Please describe the problem you are having in as much detail as possible: Receiving audio does not work. Whole code of my bot is pasted below. I don’t have any output in console, except information about bot logging. If i change stream to write file instead of playing it to same channel it just writes an empty file. Include a reproducible code sample here, if possible:

import "dotenv/config";
import { Client } from "discord.js";

const client = new Client();

client.on("ready", () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

client.on("message", async (msg) => {
  if (msg.content === "listen") {
    const connection = await msg.member.voice.channel.join();
    const userId = msg.member.id;
    const audio = connection.receiver.createStream(userId, {
      mode: "opus",
      end: "manual",
    });
    audio
      .on("data", (chunk) => console.log(chunk))
      .on("close", () => console.log("close"))
      .on("error", (e) => console.log(e))
      .on("readable", () => console.log("readable"))
      .on("close", () => console.log("closed"));
    connection.play(audio, { type: "opus" });
  }
});

client.login(process.env.DISCORD_TOKEN);

Further details:

  • discord.js version: 12.2.0
  • Node.js version: 12.6.0 (but I am using babel-node)
  • Operating system: Windows 10
  • Priority this issue should have – please be realistic and elaborate if possible: idk
  • [x ] I have also tested the issue on latest master, commit hash: d827544fbd12e827fb4b6ff99d8894ecd79ede02 and 99612ba14dc70462c878fe8e34a003c4b2325ad3

I guess I should reference to https://github.com/discordapp/discord-api-docs/issues/808 this issue here

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Clemens-Ecommented, May 8, 2020

Receiving voice works fine, the problem lies in a weird bug that your code triggers. I noticed weird behavior when trying to play a stream that origins from the same connection. I don’t know if its d.js or discords fault, but when trying to play the stream on the same connection, that you just created it from, no data is being received.

Try removing

connection.play(audio, { type: "opus" });

To check if you now receive voice. Here is my hack around the problem doing a setTimeout somehow does the trick.

Additional Info: When playing the just created stream in a different connection, there are no issues, it only happens while playing it within the same connection, which makes the bug even weirder

1reaction
castdriancommented, May 4, 2020

you need to send audio before you can receive. there was PR that should have handled that by sending a silence frame. Yet I have to send the silence buffer manually aswell, so I suggest you do that too

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fix problems sending, receiving or connecting to Messages
If you get a notification that your computer can't connect to Messages, try these steps: On your phone, turn your Wi-Fi off and...
Read more >
Troubleshoot audio and video issues on your computer or ...
Running the audio troubleshooter may help resolve your issue, but it requires administrative access to your computer. To run troubleshooting ...
Read more >
VoIP Troubleshooting: 5 Fixes for Common Connection Issues
Problem #1: Networking and LAN Issues · Unplug power to the router. Wait 30 seconds. Plug the cord back in. · Set up...
Read more >
How to troubleshoot low volume or no sound from the ... - Sony
Attempt to increase the volume level. Make sure no headphones are connected to the A/V receiver. Replace the speaker wires. Try connecting a ......
Read more >
If you can't make or receive a FaceTime call on your iPhone or ...
You need a cellular or Wi-Fi connection to use FaceTime on your iPhone or iPad. Otherwise, you might have issues for one of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found