Discord.Net-Labs icon indicating copy to clipboard operation
Discord.Net-Labs copied to clipboard

Moving bot causes disconnect

Open Otixa opened this issue 3 years ago • 5 comments

I've noticed that moving a barebones bot from one channel to the other seems to cause it to disconnect. The bot only has a Ready event handler that finds the "General" voice channel and joins it. After moving it to a different channel, the bot disconnects. Any help and/or hints would be greatly appreciated.

Upon further inspection, I have found the following:

05:04:18 Audio #1    Heartbeat Stopped
05:04:18 Audio #1    Keepalive Stopped
05:04:18 Audio #1    System.Exception: WebSocket connection was closed
 ---> Discord.Net.WebSocketClosedException: The server sent close 4014: "Disconnected."
   at Discord.Net.WebSockets.DefaultWebSocketClient.RunAsync(CancellationToken cancelToken)
   --- End of inner exception stack trace ---
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
05:04:18 Audio #1    Failed to start the connection: System.Exception: WebSocket connection was closed ---> Discord.Net.WebSocketClosedException: The server sent close 4014: "Disconnected."   at Discord.Net.WebSockets.DefaultWebSocketClient.RunAsync(CancellationToken cancelToken)   --- End of inner exception stack trace ---   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext():
System.Exception: WebSocket connection was closed
 ---> Discord.Net.WebSocketClosedException: The server sent close 4014: "Disconnected."
   at Discord.Net.WebSockets.DefaultWebSocketClient.RunAsync(CancellationToken cancelToken)
   --- End of inner exception stack trace ---
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
05:04:18 Audio #1    Disconnecting
05:04:18 Audio #1    Disconnecting ApiClient
05:04:18 Audio #1    Waiting for heartbeater
05:04:18 Audio #1    Sending Voice State
05:04:18 Gateway     Sent VoiceStateUpdate
05:04:18 Audio #1    Disconnected
05:04:18 Audio #1    Failed to start the connection: System.Exception: WebSocket connection was closed ---> Discord.Net.WebSocketClosedException: The server sent close 4014: "Disconnected."   at Discord.Net.WebSockets.DefaultWebSocketClient.RunAsync(CancellationToken cancelToken)   --- End of inner exception stack trace ---   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext():
System.Exception: WebSocket connection was closed
 ---> Discord.Net.WebSocketClosedException: The server sent close 4014: "Disconnected."
   at Discord.Net.WebSockets.DefaultWebSocketClient.RunAsync(CancellationToken cancelToken)
   --- End of inner exception stack trace ---
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
05:04:18 Gateway     Received Dispatch (VOICE_STATE_UPDATE)

Otixa avatar Sep 28 '21 02:09 Otixa

Can you show the code that is calling this code? @Otixa

emillly-b avatar Oct 01 '21 17:10 emillly-b

Can you show the code that is calling this code? @Otixa

I think his error happens when you drag the bot to another voice channel on discord, not particularly any code.

Upon further inspection, I have found the following:

What's weird is the bot should just reconnect the voice socket to the new channel. this shouldn't cause the main socket to die

quinchs avatar Oct 01 '21 18:10 quinchs

I think his error happens when you drag the bot to another voice channel on discord, not particularly any code.

@quinchs is correct. It seems to be some issue deep down not related to any specific implementation code.

What's weird is the bot should just reconnect the voice socket to the new channel. this shouldn't cause the main socket to die

It is weird. I've tried doing it several different ways and always get the same result.

As an update, since creating the issue I've tried to replicate this in Discord.Net vanilla and it seems to be happening there as well. DSharpPlus does not exhibit the same behavior.

Otixa avatar Oct 03 '21 19:10 Otixa

image

Exception is thrown by design in DefaultWebSocketClient

I've found a similar issue in another Discord lib: https://github.com/abalabahaha/eris/pull/1178

emillly-b avatar Oct 12 '21 20:10 emillly-b

This should be reworked to seamlessly allow switching between voice channels without disrupting the socket on the dev end.

quinchs avatar Oct 12 '21 21:10 quinchs