discord.py icon indicating copy to clipboard operation
discord.py copied to clipboard

Voice woes: moving channels via client drag and region changes break voice connection

Open imayhaveborkedit opened this issue 3 years ago • 2 comments

Summary

Voice code does not properly reconnect to voice upon being moved to a different channel and possibly from a region change.

Reproduction Steps

Join the bot to voice channel A. Then either:

  • Drag the bot to voice channel B
  • Drag the bot back to voice channel A (or any other)

or

  • Change the voice region

Minimal Reproducible Code

Mostly reproduced in the client but there is one peculiar thing to note. Dragging the bot between channels in the client breaks it differently than moving channels with voice_client.move_to. For example:

vch1 = guild.get_channel(123)
vch2 = guild.get_channel(456)

await vc = vch1.connect()
await vc.move_to(vch2)
await vc.move_to(vch1)
await vc.move_to(vch2)
await vc.move_to(vch1)
await vc.move_to(vch2)
await vc.move_to(vch1)

The bot seemingly changes channel properly, however the log output is a bit strange. See footnote 1.

In the other case, it's simply changing the voice region via client or await channel.edit(rtc_region="..."). See footnote 2.

Expected Results

Naturally, it should just work.

Actual Results

Bizarre breakage and bad connection state.

Intents

All

System Information

  • Python v3.11.3-final
  • discord.py v2.2.2-final
  • aiohttp v3.8.4
  • system info: Windows 10 10.0.19045

Checklist

  • [X] I have searched the open issues for duplicates.
  • [X] I have shown the entire traceback, if possible.
  • [X] I have removed my token from display, if visible.

Additional Context

I'm fairly sure this is a regression and I don't know if it has anything to do with https://github.com/Rapptz/discord.py/commit/21ed9f61d2b2f44c0cd43fecbb7f1ea77f920596, but I'll look into this more later.

Additionally, one other person has tried this in the discord server and their breakage is different from mine. See: https://discord.com/channels/336642139381301249/336642776609456130/1097363280332337263 and the video shortly after that.

[1]

[2023-04-17 00:13:04] [INFO    ] discord.voice_client: Connecting to voice...
[2023-04-17 00:13:04] [INFO    ] discord.voice_client: Starting voice handshake... (connection attempt 1)
[2023-04-17 00:13:04] [INFO    ] discord.voice_client: Voice handshake complete. Endpoint found us-east6118.discord.media
[2023-04-17 00:13:13] [INFO    ] discord.voice_client: Disconnected from voice by force... potentially reconnecting.
[2023-04-17 00:13:13] [INFO    ] discord.voice_client: Starting voice handshake... (connection attempt 2)
[2023-04-17 00:13:13] [INFO    ] discord.voice_client: Voice handshake complete. Endpoint found us-east7023.discord.media
[2023-04-17 00:13:23] [INFO    ] discord.voice_client: Disconnected from voice by force... potentially reconnecting.
[2023-04-17 00:13:23] [INFO    ] discord.voice_client: Starting voice handshake... (connection attempt 3)
[2023-04-17 00:13:23] [INFO    ] discord.voice_client: Voice handshake complete. Endpoint found us-east5289.discord.media
[2023-04-17 00:13:43] [INFO    ] discord.voice_client: Disconnected from voice by force... potentially reconnecting.
[2023-04-17 00:13:43] [INFO    ] discord.voice_client: Starting voice handshake... (connection attempt 4)
[2023-04-17 00:13:43] [INFO    ] discord.voice_client: Voice handshake complete. Endpoint found us-east7388.discord.media
[2023-04-17 00:13:48] [INFO    ] discord.voice_client: Disconnected from voice by force... potentially reconnecting.
[2023-04-17 00:13:48] [INFO    ] discord.voice_client: Starting voice handshake... (connection attempt 5)
[2023-04-17 00:13:48] [INFO    ] discord.voice_client: Voice handshake complete. Endpoint found us-east4334.discord.media
Unclosed connection
client_connection: Connection<ConnectionKey(host='us-east6118.discord.media', port=443, is_ssl=True, ssl=None, proxy=None, proxy_auth=None, proxy_headers_hash=None)>
Unclosed connection
client_connection: Connection<ConnectionKey(host='us-east7023.discord.media', port=443, is_ssl=True, ssl=None, proxy=None, proxy_auth=None, proxy_headers_hash=None)>
Unclosed connection
client_connection: Connection<ConnectionKey(host='us-east5289.discord.media', port=443, is_ssl=True, ssl=None, proxy=None, proxy_auth=None, proxy_headers_hash=None)>
Unclosed connection
client_connection: Connection<ConnectionKey(host='us-east7388.discord.media', port=443, is_ssl=True, ssl=None, proxy=None, proxy_auth=None, proxy_headers_hash=None)>
[2023-04-17 00:13:52] [INFO    ] discord.voice_client: Disconnected from voice by force... potentially reconnecting.
[2023-04-17 00:13:52] [INFO    ] discord.voice_client: Starting voice handshake... (connection attempt 6)
[2023-04-17 00:13:52] [INFO    ] discord.voice_client: Voice handshake complete. Endpoint found us-east7023.discord.media

[2]

I'm not entire sure if the state here is broken, but there is a ws close exception with code 4000 for me.

[2023-04-17 00:26:17] [INFO    ] discord.voice_client: Connecting to voice...
[2023-04-17 00:26:17] [INFO    ] discord.voice_client: Starting voice handshake... (connection attempt 1)
[2023-04-17 00:26:17] [INFO    ] discord.voice_client: Voice handshake complete. Endpoint found us-east6442.discord.media
[2023-04-17 00:26:32] [ERROR   ] discord.voice_client: Disconnected from voice... Reconnecting in 1.87s.
Traceback (most recent call last):
  File "C:\Python\Python3.11\Lib\site-packages\discord\voice_client.py", line 456, in poll_voice_ws
    await self.ws.poll_event()
  File "C:\Python\Python3.11\Lib\site-packages\discord\gateway.py", line 1006, in poll_event
    raise ConnectionClosed(self.ws, shard_id=None, code=self._close_code)
discord.errors.ConnectionClosed: Shard ID None WebSocket closed with 4000
[2023-04-17 00:26:34] [INFO    ] discord.voice_client: The voice handshake is being terminated for Channel ID 124808142688092160 (Guild ID 124808140838404096)
[2023-04-17 00:26:34] [INFO    ] discord.voice_client: Connecting to voice...
[2023-04-17 00:26:34] [INFO    ] discord.voice_client: Starting voice handshake... (connection attempt 2)
[2023-04-17 00:26:34] [INFO    ] discord.voice_client: Voice handshake complete. Endpoint found japan11113.discord.media

imayhaveborkedit avatar Apr 17 '23 04:04 imayhaveborkedit

I am having this issue as well, but it's affecting me when the client is disconnected by another user.

sedley avatar Apr 18 '23 07:04 sedley

Wenn dragging it in the client, I can't reproduce the Unclosed connection output. When I want to move with move_with I get this warning after 2 moves:

WARNING  discord.gateway Shard ID None has stopped responding to the gateway. Closing and restarting.

So I can't really reproduce your errors

codeofandrin avatar Apr 18 '23 17:04 codeofandrin