solaluset / DandelionMusic

Discord music bot written in Python that supports YouTube, SoundCloud, Spotify, Bandcamp, Twitter and custom files
GNU General Public License v3.0
42 stars 17 forks source link

Common question about connection (websocket) flow handling #112

Closed SenninMoodo closed 7 months ago

SenninMoodo commented 8 months ago

Hey, this prolly don't belong in the issues tab but I wasn't able to find any discussionn tab or similar to ask.

As I'm using the bot for quite a while now I noticed that it reconnects itself properly and won't stop streaming the audio. I'm currently trying to set up a little bot for a livestream as well but noticed with the help of the logger that the websocket connection randomly gets closed from time to time. It seems this is the common discord connection flow so nothing you can really do about it but when the connection closes my bot obv leaves the voice channel and doesn't reconnect and resume playing.

My idea was to write an error handler with the on_error event but just wanted to quickly ask how you managed to get rid off that "issue". I guess you should've encountered the same while developing your bot.

Any hint is kindly appreciated.

solaluset commented 8 months ago

Funny thing is, I still notice the bot disconnecting sometimes.

The only thing I can suggest is using reconnect=True (which is the default AFAIK) when connecting to a voice channel.

You can also try adapting my on_voice_state_update (which was originally added to properly resume playing when bot is moved to other channel): https://github.com/solaluset/DandelionMusic/blob/efd5dcff3422cf927630b92d1f042259fa9b01bf/musicbot/bot.py#L93-L116

SenninMoodo commented 8 months ago

I had your bot running from mid Dec- end of Jan without any dc (at least without any visual one which wasn't reconnected)

And yeah I had the idea with the on_voice_state_update event as well wasn't just quite sure if there is a proper way to handle it.

Funny thing is, I still notice the bot disconnecting sometimes.

The only thing I can suggest is using reconnect=True (which is the default AFAIK) when connecting to a voice channel.

You can also try adapting my on_voice_state_update (which was originally added to properly resume playing when bot is moved to other channel):

https://github.com/solaluset/DandelionMusic/blob/efd5dcff3422cf927630b92d1f042259fa9b01bf/musicbot/bot.py#L93-L116

solaluset commented 8 months ago

Have you managed to implement it?