discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.36k stars 3.97k forks source link

Broadcast stops playing after a certain time on some channels #5531

Closed weslinho closed 3 years ago

weslinho commented 3 years ago

Please describe the problem you are having in as much detail as possible:

Im developing a radio bot, using discords Broadcast system. After a time connected in a call, the bot simply stops playing the broadcast on the call and only resumes if it is reconnected. I already tested if it was enough to change the broadcast or just use the .play(<broadcast>) method again but I wasnt successful. It doesnt happen on all channels at the same time, each time a channel is affected by the problem. No errors are returned.

Further details:

SamuelScheit commented 3 years ago

@trywesley Can you attach the debug log by adding these loggers to your bot/client event listener:

client.on("debug", console.log)
client.on("error", console.error)
client.on("warn", console.warn)
vladh commented 3 years ago

I'm also experiencing this issue. My audio stops playing after approximately 350–450 seconds.

I've added the above logs, and when the audio stops playing, I get this message:

[VOICE (705543688167620708:0)]: [WS] >> {"op":5,"d":{"speaking":0,"delay":0,"ssrc":750412}}

Issues #4007 and #4021 seem related.

I'm playing the audio by passing in a URL to an MP3 file. I'm going to try and save the file locally to see if that helps.

SamuelScheit commented 3 years ago

@vladh @trywesley Could you both show/send the code you are using to play the File/URL. Also if you are you using ytdl try setting the highWaterMark option to e.g. 8mb: 1024 * 1024 * 8

vladh commented 3 years ago

The code I was using is basically just this (simplified):

  const connection = message.member.voice.channel.join();
  const dispatcher = connection.play('https://traffic.megaphone.fm/GLT7484278234.mp3?updated=1614292769#t=0');

I'm not using ytdl.

Right now I've changed it to download the file and just play it off the disk, so:

  const dispatcher = connection.play('./some-file.mp3');

It's been playing for the past 600 seconds, so I think the issue was with the connection to the server serving the MP3 file. Perhaps something causes it to be prematurely terminated. I'll keep you updated.

vladh commented 3 years ago

Update: I've saved the file locally before playing it, and playback doesn't stop anymore. It's probably a good idea to save the file anyway, so, it's all good.

Most likely, the code that does the HTTP request to get the file only manages to download some initial chunk of it. Maybe it's a Connection: keep-alive thing, or a Range thing…I'm not sure how it's done in the library. Either way, at least we've narrowed the problem down.

jack3898 commented 3 years ago

I must say, I have this same problem with ytdl-core-discord (which may inherit the problem from ytdl-core). Which further makes me think that there is some HTTP related issue. 🤔

masterjanic commented 3 years ago

I have a similiar problem. I am also playing an url stream with the broadcast dispatcher. (No yt-dl library) After arround 1-3 hours the stream stops playing in some voice channels. If I rejoin the bot to the voice channel, the stream is working perfectly fine again. It is like the channel dispatcher is re-subscribing to the broadcast when rejoining. So the broadcast dispatcher seems to work.

amishshah commented 3 years ago

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 (https://github.com/discordjs/discord.js/pull/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: