I haven't been able to resolve it myself for hours and I feel like it's not the code but possibly discord's end. I've been looking for support so I hope this is the right place.
Shard ID None WebSocket closed with 4006
Code:
import discord
from discord.ext import commands
from config import TOKEN
VOICE_CHANNEL_ID = [a valid one]
AUDIO_FILE = "vineboom.mp3"
intents = discord.Intents.default()
intents.voice_states = True
bot = commands.Bot(command_prefix="`", intents=intents)
@bot.event
async def on_ready():
print(f"Logged in as {bot.user}")
channel = bot.get_channel(VOICE_CHANNEL_ID)
if channel:
vc = await channel.connect()
vc.play(discord.FFmpegPCMAudio(AUDIO_FILE))
bot.run(TOKEN)
Steps taken so far to resolve problem:
Libraries updated:
Discord_py-2.5.2
PyNaCl-1.5.0
aiohttp-3.12.13
Fresh install of python 3.13.5
Restarting code, restarting pc, restarting internet. Kicking and re inviting bot, changing bot token.
Snippet of the log:
2025-06-14 19:09:30 INFO discord.voice_state Starting voice handshake... (connection attempt 1)
2025-06-14 19:09:30 INFO discord.voice_state Voice handshake complete. Endpoint found: c-iad08-a5e02106.discord.media
2025-06-14 19:09:30 ERROR discord.voice_state Failed to connect to voice... Retrying in 1.0s...
Traceback (most recent call last):
File "C:\Python313\Lib\site-packages\discord\voice_state.py", line 413, in _inner_connect
await self._handshake_websocket()
File "C:\Python313\Lib\site-packages\discord\voice_state.py", line 583, in _handshake_websocket
await self.ws.poll_event()
File "C:\Python313\Lib\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```