pycord icon indicating copy to clipboard operation
pycord copied to clipboard

Bot can't connect to voice chat

Open PWDSerialgamer07 opened this issue 5 months ago • 9 comments

Summary

When trying to connect to a channel, the bot will hang for some time, then disconnect.

Reproduction Steps

  1. Make the bot connect to a voice channel
  2. It doesn't work

Minimal Reproducible Code

@bot.slash_command(name="join", description="Tells the bot to join the voice channel.")
async def join(interaction: discord.Interaction) -> None:
    user = interaction.user
    await interaction.response.defer()
    if not user.voice:
        await interaction.followup.send(f"{user.name} is not connected to a voice channel.", ephemeral=True)
        return

    channel = user.voice.channel
    try:
         await channel.connect()
    except Exception as e:
         print(e)
    await interaction.followup.send(f"Connected to {channel.name}")

Expected Results

The bot connects to the voice channel

Actual Results

It connects, hangs there for some time then disconnects. Here is all that was outputted to the console:

Unclosed connection
client_connection: Connection<ConnectionKey(host='c-ams15-6ef27d2f.discord.media', port=443, is_ssl=True, ssl=True, proxy=None, proxy_auth=None, proxy_headers_hash=None)>

(that's it, there was nothing else)

Intents

default, voice states and message content

System Information

  • Python v3.11.2-final
  • py-cord v2.6.1-final
  • aiohttp v3.12.14
  • system info: Linux 6.1.0-28-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.119-1 (2024-11-22)

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

No response

PWDSerialgamer07 avatar Jul 24 '25 20:07 PWDSerialgamer07

Does #2812 fix your issue?

Icebluewolf avatar Jul 25 '25 01:07 Icebluewolf

I have the same problem i tried to connect with python3.13 with audioop-lts and just on python3.11

2025-08-26 17:38:27,086 - INFO - Connecting to voice... 2025-08-26 17:38:27,086 - INFO - Starting voice handshake... (connection attempt 1) 2025-08-26 17:38:27,598 - INFO - Voice handshake complete. Endpoint found c-ams08-12991184.discord.media 2025-08-26 17:38:27,705 - ERROR - Failed to connect to voice... Retrying... Traceback (most recent call last): File "/opt/bot/.venv/lib/python3.11/site-packages/discord/voice_client.py", line 404, in connect self.ws = await self.connect_websocket() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/bot/.venv/lib/python3.11/site-packages/discord/voice_client.py", line 375, in connect_websocket await ws.poll_event() File "/opt/bot/.venv/lib/python3.11/site-packages/discord/gateway.py", line 955, 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-26 17:38:28,708 - INFO - The voice handshake is being terminated for Channel ID <CHANNEL_ID> (Guild ID <GUILD_ID>) 2025-08-26 17:38:28,708 - INFO - Starting voice handshake... (connection attempt 2) 2025-08-26 17:38:29,109 - INFO - Voice handshake complete. Endpoint found c-ams08-12991184.discord.media 2025-08-26 17:38:29,193 - ERROR - Failed to connect to voice... Retrying... Traceback (most recent call last): File "/opt/bot/.venv/lib/python3.11/site-packages/discord/voice_client.py", line 404, in connect self.ws = await self.connect_websocket() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/bot/.venv/lib/python3.11/site-packages/discord/voice_client.py", line 375, in connect_websocket await ws.poll_event() File "/opt/bot/.venv/lib/python3.11/site-packages/discord/gateway.py", line 955, 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-26 17:38:32,197 - INFO - The voice handshake is being terminated for Channel ID <CHANNEL_ID> (Guild ID <GUILD_ID>) 2025-08-26 17:38:32,197 - INFO - Starting voice handshake... (connection attempt 3) 2025-08-26 17:38:32,625 - INFO - Voice handshake complete. Endpoint found c-ams08-12991184.discord.media 2025-08-26 17:38:32,736 - ERROR - Failed to connect to voice... Retrying... Traceback (most recent call last): File "/opt/bot/.venv/lib/python3.11/site-packages/discord/voice_client.py", line 404, in connect self.ws = await self.connect_websocket() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/bot/.venv/lib/python3.11/site-packages/discord/voice_client.py", line 375, in connect_websocket await ws.poll_event() File "/opt/bot/.venv/lib/python3.11/site-packages/discord/gateway.py", line 955, 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-26 17:38:37,737 - INFO - The voice handshake is being terminated for Channel ID <CHANNEL_ID> (Guild ID <GUILD_ID>) 2025-08-26 17:38:37,737 - INFO - Starting voice handshake... (connection attempt 4) 2025-08-26 17:38:38,121 - INFO - Voice handshake complete. Endpoint found c-ams08-12991184.discord.media 2025-08-26 17:38:38,214 - ERROR - Failed to connect to voice... Retrying... Traceback (most recent call last): File "/opt/bot/.venv/lib/python3.11/site-packages/discord/voice_client.py", line 404, in connect self.ws = await self.connect_websocket() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/bot/.venv/lib/python3.11/site-packages/discord/voice_client.py", line 375, in connect_websocket await ws.poll_event() File "/opt/bot/.venv/lib/python3.11/site-packages/discord/gateway.py", line 955, 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-26 17:38:45,218 - INFO - The voice handshake is being terminated for Channel ID <CHANNEL_ID> (Guild ID <GUILD_ID>) 2025-08-26 17:38:45,218 - INFO - Starting voice handshake... (connection attempt 5) 2025-08-26 17:38:45,610 - INFO - Voice handshake complete. Endpoint found c-ams08-12991184.discord.media 2025-08-26 17:38:45,703 - ERROR - Failed to connect to voice... Retrying... Traceback (most recent call last): File "/opt/bot/.venv/lib/python3.11/site-packages/discord/voice_client.py", line 404, in connect self.ws = await self.connect_websocket() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/bot/.venv/lib/python3.11/site-packages/discord/voice_client.py", line 375, in connect_websocket await ws.poll_event() File "/opt/bot/.venv/lib/python3.11/site-packages/discord/gateway.py", line 955, 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-26 17:38:54,705 - INFO - The voice handshake is being terminated for Channel ID <CHANNEL_ID> (Guild ID <GUILD_ID>)

and idk what #2812 did i did updated pycord but didnt help

sk3nn1xxx avatar Aug 26 '25 15:08 sk3nn1xxx

We're pretty much aware of problems. Someone is researching more about voice and trying to fix stuff soon

Lulalaby avatar Aug 26 '25 15:08 Lulalaby

We're pretty much aware of problems. Someone is researching more about voice and trying to fix stuff soon

idk i dont understand how this works but pip install --upgrade git+https://github.com/Pycord-Development/pycord.git@2ae01b7

this fixed it idk why #2812 isnt just included when i do pip install py-cord or py-cord[voice]

sk3nn1xxx avatar Aug 26 '25 15:08 sk3nn1xxx

this fixed it idk why #2812 isnt just included when i do pip install py-cord or py-cord[voice]

Because we haven't done a release for a long time lol To get the current master changes you need to use the git dependency

Lulalaby avatar Aug 26 '25 16:08 Lulalaby

Is there a plan when the fix is gonna be included in a stable release? I'm currently developing a musicbot implementation for my bot, but its impossible to ship like this as voice connection can just fail from one second to the next.

adrianfurgol avatar Aug 31 '25 17:08 adrianfurgol

Probably not in the near future cuz the voice topic is delicate

Lulalaby avatar Aug 31 '25 17:08 Lulalaby

The 4006 fix is already available on py-cord 2.7.0rc1

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

Probably not in the near future cuz the voice topic is delicate

but then the stable version isnt stable hmmmm

sk3nn1xxx avatar Sep 24 '25 19:09 sk3nn1xxx