Error 4006 causing bot to repeatedly connect to vc and fail
Summary
Previously working bot fails to join a VC, gives "WebSocket closed with 4006"
Reproduction Steps
Normal voice channel bot, just try to connect to a vc.
Minimal Reproducible Code
Expected Results
Bot should connect, and stay connected to VC.
Actual Results
Bot connects, instantly disconnects. Repeats several times until it gives up.
bot-1 | 2025-06-15 05:50:57 INFO discord.voice_state Connecting to voice...
bot-1 | 2025-06-15 05:50:57 INFO discord.voice_state Starting voice handshake... (connection attempt 1)
bot-1 | 2025-06-15 05:50:58 INFO discord.voice_state Voice handshake complete. Endpoint found: c-ewr01-daf118b6.discord.media
bot-1 | 2025-06-15 05:50:58 ERROR discord.voice_state Failed to connect to voice... Retrying in 1.0s...
bot-1 | Traceback (most recent call last):
bot-1 | File "/usr/local/lib/python3.11/site-packages/discord/voice_state.py", line 413, in _inner_connect
bot-1 | await self._handshake_websocket()
bot-1 | File "/usr/local/lib/python3.11/site-packages/discord/voice_state.py", line 583, in _handshake_websocket
bot-1 | await self.ws.poll_event()
bot-1 | File "/usr/local/lib/python3.11/site-packages/discord/gateway.py", line 1039, in poll_event
bot-1 | raise ConnectionClosed(self.ws, shard_id=None, code=self._close_code)
bot-1 | discord.errors.ConnectionClosed: Shard ID None WebSocket closed with 4006
bot-1 | 2025-06-15 05:50:58 INFO discord.voice_state The voice handshake is being terminated for Channel ID 7XXXXXXXXXXX8 (Guild ID 7XXXXXXXXXXX4)
bot-1 | 2025-06-15 05:50:59 INFO discord.voice_state Starting voice handshake... (connection attempt 2)
... (more attempts)
Intents
Necessary for voice
System Information
Oracle vps, ARM, in docker, python 3.11, latest discord.py
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
Bot worked without issues for years, until today. I already tried a clean install, and resetting the bot token. Seems like others are having a similar issue: https://stackoverflow.com/questions/79664160/discord-py-bot-keeps-reconnected-and-disconnecting-from-voice-channels
yeah i have a music bot works flawlessly then randomly i got this problem and it seems to be that when i request it to join the call it will leave and join like 6 times then give up and ill get these exact same errors. I checked the code dosent seem to be an issue
We've found the solution to this bug, I will PR a fix soon
We've found the solution to this bug, I will PR a fix soon
Thank you. In the meantime, is there a fork/branch/workaround I can use?
Can confirm, having this same issue on my TTS bot. Fix would be very helpful as this is an accessibility tool.
@DA-344 has an open PR https://github.com/Rapptz/discord.py/pull/10210
YES IM NOT THE ONLY ONE THANK YOU
Really glad I'm not the only one having this problem. I run a bot called "CheersBot V2" and it seems to be having trouble on manual and automatic join (to Voice Channels).
I am glad to see I am not the only one observing this issue, and even gladder to see a fix is already underway. I spent far too many hours hitting my head against the wall trying to debug my code or my discord bot permissions or even the discord guild voice channel settings. I am loking forward to seeing the fix released :)
The error is still present, but only occurs on US Discord servers.
The error is still present, but only occurs on US Discord servers.
Is there any server you recommend using for voice channels?
The error is still present, but only occurs on US Discord servers.
Is there any server you recommend using for voice channels?
Rotteradm, India and Brazil are ok for me. Works good.
Still having this issue with discord-py 2.5.2 on Python 3.13.5, I ran some tests on each region, the only regions I found that consistently fail are Rotterdam, US East and US West, the rest function fine.
The fix is not merged yet, so the issue is still up.
As far as I can tell, all servers fail except those in Europe, e.g. Rotterdam works without issue.
What version are you expecting this fix to be packaged in?
This fix will be released in 2.6, but you can install the master branch to use it.
Do we have a guess as to when we'll see 2.6?
Oh man!! Had this issue too
My bot has this issue as well. It was running perfectly fine for almost a year until recently. Will we receive a hot fix for this in the near future?
Same stuff :(
私の環境の場合特定のVCチャンネルで発生するようになりました。同一のサーバーであってもVCチャンネルが異なれば問題なく動作します。 具体的にそうなった経緯は、なんらかのアクションをBotに行わせている最中にDiscord botをVCから切断しました(ユーザーの権限によるもの、disconnect()は利用していない)。 その後、元のVCチャンネルに再度接続できなくなりました。 DiscordBotの再起動、再接続にあたって待機時間を干渉させるなどして試しましたが接続できませんでした。 唯一試していないのであればホスト機の再起動ですがおそらく関係ないと思います。 これが意味するものとして、Discord.pyの問題もありますが、Discordサーバー側のロジックの問題が想定されます。 これはリージョンjapanで確認しました
Currently having the same issue as @zigzag1001. This happens 40% of the time and varies by channel for some odd reason. It was working on a channel for the past while, but it stopped working now.
2025-08-16 02:28:46 INFO discord.voice_state The voice handshake is being terminated for Channel ID 1271122133916844163 (Guild ID 296861332253179905)
2025-08-16 02:28:46 ERROR discord.voice_state Error connecting to voice... disconnecting
Traceback (most recent call last):
File "C:\Users\Kip\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\discord\voice_state.py", line 384, in _wrap_connect
await self._connect(*args)
File "C:\Users\Kip\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\discord\voice_state.py", line 429, in _connect
await asyncio.wait_for(
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.12_3.12.2800.0_x64__qbz5n2kfra8p0\Lib\asyncio\tasks.py", line 520, in wait_for
return await fut
^^^^^^^^^
File "C:\Users\Kip\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\discord\voice_state.py", line 413, in _inner_connect
await self._handshake_websocket()
File "C:\Users\Kip\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\discord\voice_state.py", line 583, in _handshake_websocket
await self.ws.poll_event()
File "C:\Users\Kip\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\discord\gateway.py", line 1039, in poll_event
raise ConnectionClosed(self.ws, shard_id=None, code=self._close_code)
discord.errors.ConnectionClosed: Shard ID None WebSocket closed with 4006
2025-08-16 02:28:46 INFO discord.voice_state The voice handshake is being terminated for Channel ID 1271122133916844163 (Guild ID 296861332253179905)
I have a workaround for the issue on my end. This issue doesn't happen in Python 3.12, but it happens in 3.8.
It's not related to Python versions, but to voice regions. The fix is available on the master branch.
2025-09-08 13:25:56 INFO discord.voice_state Starting voice handshake... (connection attempt 5)
2025-09-08 13:25:57 INFO discord.voice_state Voice handshake complete. Endpoint found: c-sin12-ef767469.discord.media
2025-09-08 13:25:57 ERROR discord.voice_state Failed to connect to voice... Retrying in 9.0s...
Traceback (most recent call last):
File "C:\Users\HP\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\discord\voice_state.py", line 413, in _inner_connect
await self._handshake_websocket()
File "C:\Users\HP\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\discord\voice_state.py", line 583, in _handshake_websocket
await self.ws.poll_event()
File "C:\Users\HP\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\discord\gateway.py", line 1039, in poll_event
raise ConnectionClosed(self.ws, shard_id=None, code=self._close_code)
discord.errors.ConnectionClosed: Shard ID None WebSocket closed with 4006
2025-09-08 13:25:57 INFO discord.voice_state The voice handshake is being terminated for Channel ID 1414495632865103882 (Guild ID 1333965207130603622)
2025-09-08 13:26:06 INFO discord.voice_state Voice connection complete.
2025-09-08 13:26:06 INFO discord.voice_state Disconnecting from voice normally, close code 1000.
2025-09-08 13:26:06 INFO discord.voice_state The voice handshake is being terminated for Channel ID 1414495632865103882 (Guild ID 1333965207130603622)
I'm Same...
2025-09-08 13:25:56 INFO discord.voice_state Starting voice handshake... (connection attempt 5) 2025-09-08 13:25:57 INFO discord.voice_state Voice handshake complete. Endpoint found: c-sin12-ef767469.discord.media 2025-09-08 13:25:57 ERROR discord.voice_state Failed to connect to voice... Retrying in 9.0s... Traceback (most recent call last): File "C:\Users\HP\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\discord\voice_state.py", line 413, in _inner_connect await self._handshake_websocket() File "C:\Users\HP\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\discord\voice_state.py", line 583, in _handshake_websocket await self.ws.poll_event() File "C:\Users\HP\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\discord\gateway.py", line 1039, in poll_event raise ConnectionClosed(self.ws, shard_id=None, code=self._close_code) discord.errors.ConnectionClosed: Shard ID None WebSocket closed with 4006 2025-09-08 13:25:57 INFO discord.voice_state The voice handshake is being terminated for Channel ID 1414495632865103882 (Guild ID 1333965207130603622) 2025-09-08 13:26:06 INFO discord.voice_state Voice connection complete. 2025-09-08 13:26:06 INFO discord.voice_state Disconnecting from voice normally, close code 1000. 2025-09-08 13:26:06 INFO discord.voice_state The voice handshake is being terminated for Channel ID 1414495632865103882 (Guild ID 1333965207130603622)I'm Same...
Please update your discord.py version to the latest 2.6.3:
# be aware of any venvs
python -m pip install discord.py -U
Also, consider joining the support server for faster and easier help.
https://github.com/Rapptz/discord.py/issues/10207#issuecomment-3264856191
Oh Uhh Thanks
This still happens to me on 2.6.3 and the latest dev install. I'm in Vancouver. IDK how to fix this. ty. This is immediately fixed in any of the asian regions.
still bugged. Usually swaping regions helps but this time regions is affected