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

24/7 music bot randomly stops transmitting until restarted #1294

Closed
Foxite opened this issue Apr 23, 2022 · 12 comments
Closed

24/7 music bot randomly stops transmitting until restarted #1294

Foxite opened this issue Apr 23, 2022 · 12 comments

Comments

@Foxite
Copy link
Contributor

Foxite commented Apr 23, 2022

I have a bot that is connected to voice channels and plays the same, 6-hour raw pcm file on loop 24/7. This works fine until it randomly stops playing. I have never observed this happening, only finding it silent when I join the channel. There are no exceptions or error events. I've had this problem basically since I started running it about 6 months ago, and nothing I've tried has permanently fixed it. Restarting the bot will temporarily fix it.

The bot runs in docker, and uses .NET 5.0. Testing with a shorter audio file reveals that it's not because my code doesn't loop the track properly.

While the bot is properly playing music, cpu usage for the dotnet process is about 25% which I've been told is normal. After the bot stops transmitting, cpu usage is less than 1%.

I'm not sure at all if this is a problem with dsharpplus, my code, or my internet, but I'm pretty much out of ideas for how to fix this. If you're curious and have spare time you can look at my code here

@OoLunar
Copy link
Member

OoLunar commented Apr 23, 2022

We are looking into completely remaking VNext. You're welcome to join our Discord to see what we currently have planned or to suggest any new features you'd like to see. Thanks for the bug report, I'll leave the issue open until the rewrite releases

@Foxite
Copy link
Contributor Author

Foxite commented Apr 27, 2022

FWIW, I switched to another discord library and I'm still having this problem, so it's probably not caused by this library.

@OoLunar
Copy link
Member

OoLunar commented Apr 27, 2022

I've been having continuous trouble with Discord's voice gateway, so I'm generally unsure if there's an issue with Discord's voice gateway itself, if the lib has somehow been banned from receiving VOICE_STATE_UPDATE and VOICE_SERVER_UPDATE events or if there's just a deeply rooted lib bug that I have not yet found. I spent all day yesterday trying to fix a majority of VoiceNext bugs as a hotfix attempt, however, I didn't make any progress whatsoever.

If OTHER libs are starting to have issues with Discord's voice gateway, then that only confuses me more.

@loopyd
Copy link

loopyd commented Apr 27, 2022 via email

@Foxite
Copy link
Contributor Author

Foxite commented Apr 28, 2022

@loopyd Thanks for all the info. As for encoding transmitted audio, if I understand it correctly, audio is sent to Discord in Opus, which accounts for things like packet loss. PCM is encoded into Opus client-side. At least in Discord.NET, you can send a pre-encoded Opus stream (which I tried, and the resulting files are much smaller), but you won't get the benefits of encoding it at runtime (discord-net/Discord.Net#691). Is that right? I haven't seen a way to transmit audio in any another format in DSharpPlus.

@OoLunar
Copy link
Member

OoLunar commented Apr 28, 2022

At the current moment, DSharpPlus doesn't do any audio conversion. This is set to change in the future. As an alternative you can invoke FFMPEG or use any other audio related lib

@Foxite
Copy link
Contributor Author

Foxite commented Apr 28, 2022

I meant if audio can be sent to discord in a format other than Opus, to reduce bandwidth usage.

@OoLunar
Copy link
Member

OoLunar commented Apr 28, 2022

@Foxite
Copy link
Contributor Author

Foxite commented Apr 28, 2022

If this is a non-fixable limit imposed by discord, this issue can probably be closed as won'tfix, although it may be useful to send a log message when the voice rate limit is hit, if possible.

@OoLunar
Copy link
Member

OoLunar commented Apr 28, 2022

As I'm currently going over the voice gateway protocol, I'm not seeing anything which tells you about bandwidth or ratelimits (see Voice OpCodes and Voice Websocket Close Event Codes. I can reach out to Discord and see what they say, but the response will very likely be "Not an issue on our end, check your code instead."

Regardless, like with all other VNext issues, I'll leave it open until the rewrite releases. I'm making good progress so I would hope that the release is soon

@OoLunar
Copy link
Member

OoLunar commented Apr 30, 2022

Now that I think about it, isn't the bandwidth ratelimit defined on the channel object itself as DiscordChannel.Bitrate? Could it be that we're exceeding this bitrate which is what leads to this behavior?

@Foxite
Copy link
Contributor Author

Foxite commented May 27, 2022

To anyone reading this in the future, this problem disappeared after I made my bot only transmit audio when anyone is connected. You can track this by subscribing to VoiceStateUpdated events; there are UserJoined and UserLeft events, but UserJoined does not work properly (UserLeft does).

Update: problem still happens, but I'm not sure if this is a different problem or it wasn't fixed in the first place.

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

No branches or pull requests

4 participants