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

Error 4006 causing bot to repeatedly connect to vc and fail

Open zigzag1001 opened this issue 6 months ago • 5 comments

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

zigzag1001 avatar Jun 15 '25 06:06 zigzag1001

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

unicornlover456 avatar Jun 15 '25 16:06 unicornlover456

We've found the solution to this bug, I will PR a fix soon

DA-344 avatar Jun 15 '25 16:06 DA-344

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?

zigzag1001 avatar Jun 16 '25 02:06 zigzag1001

Can confirm, having this same issue on my TTS bot. Fix would be very helpful as this is an accessibility tool.

DigiDuncan avatar Jun 16 '25 03:06 DigiDuncan

@DA-344 has an open PR https://github.com/Rapptz/discord.py/pull/10210

Doxterpepper avatar Jun 16 '25 16:06 Doxterpepper

YES IM NOT THE ONLY ONE THANK YOU

gutbash avatar Jun 19 '25 02:06 gutbash

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).

Wubbity avatar Jun 20 '25 19:06 Wubbity

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 :)

CalvinTheRed avatar Jun 22 '25 04:06 CalvinTheRed

The error is still present, but only occurs on US Discord servers.

Sarabanga avatar Jun 22 '25 16:06 Sarabanga

The error is still present, but only occurs on US Discord servers.

Is there any server you recommend using for voice channels?

Hayato20233 avatar Jun 22 '25 22:06 Hayato20233

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.

Sarabanga avatar Jun 22 '25 22:06 Sarabanga

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.

ottergauze avatar Jun 27 '25 17:06 ottergauze

The fix is not merged yet, so the issue is still up.

DA-344 avatar Jun 27 '25 17:06 DA-344

As far as I can tell, all servers fail except those in Europe, e.g. Rotterdam works without issue.

msburgess3200 avatar Jun 28 '25 06:06 msburgess3200

What version are you expecting this fix to be packaged in?

Timber23 avatar Jun 30 '25 18:06 Timber23

This fix will be released in 2.6, but you can install the master branch to use it.

DA-344 avatar Jun 30 '25 18:06 DA-344

Do we have a guess as to when we'll see 2.6?

clockwinder avatar Jul 01 '25 18:07 clockwinder

Oh man!! Had this issue too

Exoticinurs avatar Aug 08 '25 14:08 Exoticinurs

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?

karelbondan avatar Aug 11 '25 11:08 karelbondan

Same stuff :(

PanBohdan avatar Aug 11 '25 16:08 PanBohdan

私の環境の場合特定のVCチャンネルで発生するようになりました。同一のサーバーであってもVCチャンネルが異なれば問題なく動作します。 具体的にそうなった経緯は、なんらかのアクションをBotに行わせている最中にDiscord botをVCから切断しました(ユーザーの権限によるもの、disconnect()は利用していない)。 その後、元のVCチャンネルに再度接続できなくなりました。 DiscordBotの再起動、再接続にあたって待機時間を干渉させるなどして試しましたが接続できませんでした。 唯一試していないのであればホスト機の再起動ですがおそらく関係ないと思います。 これが意味するものとして、Discord.pyの問題もありますが、Discordサーバー側のロジックの問題が想定されます。 これはリージョンjapanで確認しました

Nekomimi21336 avatar Aug 14 '25 01:08 Nekomimi21336

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)

kipuki avatar Aug 16 '25 01:08 kipuki

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.

kipuki avatar Aug 17 '25 17:08 kipuki

It's not related to Python versions, but to voice regions. The fix is available on the master branch.

DA-344 avatar Aug 17 '25 17:08 DA-344

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...

prayoadmii avatar Sep 08 '25 06:09 prayoadmii

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.

Soheab avatar Sep 08 '25 06:09 Soheab

https://github.com/Rapptz/discord.py/issues/10207#issuecomment-3264856191

Oh Uhh Thanks

prayoadmii avatar Sep 08 '25 06:09 prayoadmii

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.

adriftthesea avatar Sep 14 '25 02:09 adriftthesea

still bugged. Usually swaping regions helps but this time regions is affected

kloklojul avatar Sep 20 '25 23:09 kloklojul