discord.py: 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

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • 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

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 14
  • Comments: 17 (3 by maintainers)

Commits related to this issue

Most upvoted comments

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

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

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.

YES IM NOT THE ONLY ONE THANK YOU

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

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