PythonistaGuild / Wavelink

A powerful Lavalink library for Discord.py.
https://wavelink.dev
MIT License
391 stars 180 forks source link

ChannelTimeoutException: Unable to connect to <voice_channel_name> as it exceeded the timeout of 30.0 seconds. #328

Open Midorina opened 2 days ago

Midorina commented 2 days ago

Hello,

Since last week my bot is unable to detect that it has connected to the voice channel. When I execute the respective command, the bot joins the voice channel but halts for 30 seconds. After that the following exception with the stacktrace is thrown:

2024-10-04 17:34:14 ERROR    Midobot Cluster#0 Details of the last command error:
Traceback (most recent call last):
  File "/root/midobot/env/lib/python3.10/site-packages/wavelink/player.py", line 736, in connect
    await self._connection_event.wait()
  File "/usr/lib/python3.10/asyncio/locks.py", line 214, in wait
    await fut
asyncio.exceptions.CancelledError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/root/midobot/env/lib/python3.10/site-packages/wavelink/player.py", line 735, in connect
    async with async_timeout.timeout(timeout):
  File "/root/midobot/env/lib/python3.10/site-packages/async_timeout/__init__.py", line 141, in __aexit__
    self._do_exit(exc_type)
  File "/root/midobot/env/lib/python3.10/site-packages/async_timeout/__init__.py", line 228, in _do_exit
    raise asyncio.TimeoutError
asyncio.exceptions.TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/root/midobot/env/lib/python3.10/site-packages/discord/ext/commands/core.py", line 235, in wrapped
    ret = await coro(*args, **kwargs)
  File "/root/midobot/cogs/music.py", line 368, in _play
    await self.ensure_voice_client(ctx)
  File "/root/midobot/cogs/music.py", line 469, in ensure_voice_client
    await ctx.invoke(self._connect)
  File "/root/midobot/env/lib/python3.10/site-packages/discord/ext/commands/context.py", line 337, in invoke
    return await command(self, *args, **kwargs)
  File "/root/midobot/env/lib/python3.10/site-packages/discord/ext/commands/core.py", line 588, in __call__
    return await self.callback(self.cog, context, *args, **kwargs)  # type: ignore
  File "/root/midobot/cogs/music.py", line 111, in _connect
    vc: mido_utils.VoicePlayer = await channel.connect(cls=mido_utils.VoicePlayer)
  File "/root/midobot/env/lib/python3.10/site-packages/discord/abc.py", line 1966, in connect
    await voice.connect(timeout=timeout, reconnect=reconnect, self_deaf=self_deaf, self_mute=self_mute)
  File "/root/midobot/env/lib/python3.10/site-packages/wavelink/player.py", line 739, in connect
    raise ChannelTimeoutException(msg)
wavelink.exceptions.ChannelTimeoutException: Unable to connect to peynir as it exceeded the timeout of 30.0 seconds.

I have discord.py[voice] 2.4.0 and wavelink 3.4.1. What could be the issue? Thanks.

EvieePy commented 2 days ago

This could happen due to a few reasons.

Possibly your bot does not have permission to view and connect to the channel, you should always check this first.

You may be overriding the voice state update or voice server update events which is preventing wavelink from seeing that is has connected.

Otherwise I would try connecting to another channel and/or region, and if you can provide debug wavelink logs

Midorina commented 2 days ago

Hi,

Thanks for the quick reply. My bot has administrator permissions and it does connect to the channel.

Regarding the voice state, I only have a listener for it in my logging cog:

    @commands.Cog.listener()
    async def on_voice_state_update(self, member: discord.Member,
                                    before: discord.VoiceState | None,
                                    after: discord.VoiceState | None):
        await self.base_logging_func(LoggedEvents.VOICE_STATE_UPDATE, member, before, after)

Console logs with debug enabled:

2024-10-04 17:52:42 DEBUG    discord.client Dispatching event socket_event_type
2024-10-04 17:52:42 DEBUG    discord.state Processed a chunk for 62 members in guild ID 357889493287698433.
2024-10-04 17:52:42 INFO     Midobot Cluster#0 Chunked 62 members of guild: şapalak
2024-10-04 17:52:42 DEBUG    discord.client Dispatching event command
2024-10-04 17:52:42 DEBUG    Midobot Cluster#0 Blacklist checking took:    0.00251s
2024-10-04 17:52:42 DEBUG    Midobot Cluster#0 Attaching db objects to ctx took:   0.00303s
2024-10-04 17:52:42 DEBUG    discord.gateway Updating our voice state to {'op': 4, 'd': {'guild_id': 357889493287698433, 'channel_id': 889930605108817990, 'self_mute': False, 'self_deaf': False}}.
2024-10-04 17:52:42 DEBUG    discord.gateway For Shard ID 0: WebSocket Event: {'t': 'VOICE_STATE_UPDATE', 's': 18, 'op': 0, 'd': {'member': {'user': {'username': 'Midobot', 'public_flags': 0, 'id': '193431106647883776', 'global_name': None, 'display_name': None, 'discriminator': '5711', 'clan': None, 'bot': True, 'avatar_decoration_data': None, 'avatar': '7c4b43f1c7b037558f9856556e908263'}, 'roles': ['861694343010451496'], 'premium_since': None, 'pending': False, 'nick': None, 'mute': False, 'joined_at': '2024-08-19T23:15:40.714000+00:00', 'flags': 0, 'deaf': False, 'communication_disabled_until': None, 'banner': None, 'avatar': None}, 'user_id': '193431106647883776', 'suppress': False, 'session_id': 'e4e9da36bff4d3cdb78f8a74e8c4b33d', 'self_video': False, 'self_mute': False, 'self_deaf': False, 'request_to_speak_timestamp': None, 'mute': False, 'guild_id': '357889493287698433', 'deaf': False, 'channel_id': '889930605108817990'}}
2024-10-04 17:52:42 DEBUG    discord.client Dispatching event socket_event_type
2024-10-04 17:52:42 DEBUG    discord.client Dispatching event voice_state_update
2024-10-04 17:52:42 DEBUG    discord.gateway For Shard ID 0: WebSocket Event: {'t': 'VOICE_SERVER_UPDATE', 's': 19, 'op': 0, 'd': {'token': '9042a4b9cf150c1a', 'guild_id': '357889493287698433', 'endpoint': 'stockholm8036.discord.media:443'}}
2024-10-04 17:52:42 DEBUG    discord.client Dispatching event socket_event_type
2024-10-04 17:52:55 DEBUG    websockets.client % sending keepalive ping
2024-10-04 17:52:55 DEBUG    websockets.client > PING 'J\x14}\x14' [text, 4 bytes]
2024-10-04 17:52:55 DEBUG    websockets.client < PONG 'J\x14}\x14' [text, 4 bytes]
2024-10-04 17:52:55 DEBUG    websockets.client % received keepalive pong
2024-10-04 17:52:55 DEBUG    websockets.client < PING c0 5c d0 ad [binary, 4 bytes]
2024-10-04 17:52:55 DEBUG    websockets.client > PONG c0 5c d0 ad [binary, 4 bytes]
2024-10-04 17:53:05 DEBUG    Midobot Cluster#0 Inserting cached messages to DB took:       0.00497s
2024-10-04 17:53:05 DEBUG    Midobot Cluster#0 Checking modlogs took:              0.02170s
2024-10-04 17:53:08 DEBUG    discord.gateway For Shard ID 0: WebSocket Event: {'t': 'GUILD_MEMBER_UPDATE', 's': 20, 'op': 0, 'd': {'user': {'username': 'averitia', 'public_flags': 4194368, 'id': '253872670821580801', 'global_name': 'Averitia', 'display_name': 'Averitia', 'discriminator': '0', 'clan': None, 'bot': False, 'avatar_decoration_data': {'sku_id': '1144058844004233369', 'expires_at': None, 'asset': 'a_fed43ab12698df65902ba06727e20c0e'}, 'avatar': '97e2732b0956490ee1ff276687ef3653'}, 'roles': [], 'premium_since': None, 'pending': False, 'nick': None, 'mute': False, 'joined_at': '2021-08-20T02:36:48.378000+00:00', 'guild_id': '244403505920606210', 'flags': 0, 'deaf': False, 'communication_disabled_until': None, 'banner': None, 'avatar': None}}
2024-10-04 17:53:08 DEBUG    discord.client Dispatching event socket_event_type
2024-10-04 17:53:08 DEBUG    discord.state GUILD_MEMBER_UPDATE referencing an unknown member ID: 253872670821580801. Discarding.
2024-10-04 17:53:12 DEBUG    discord.client Dispatching event command_error
2024-10-04 17:53:12 INFO     Midobot Cluster#0 Command errored in 30.12342s:
                   Server  : şapalak (357889493287698433)
                   Channel : #bot (872918217293725726)
                   User    : midorina (90076279646212096)
                   Command : m.play more than friends
                   Error   : Command raised an exception: ChannelTimeoutException: Unable to connect to peynir as it exceeded the timeout of 30.0 seconds.
2024-10-04 17:53:12 DEBUG    discord.gateway For Shard ID 0: WebSocket Event: {'t': 'MESSAGE_CREATE', 's': 21, 'op': 0, 'd': {'type': 0, 'tts': False, 'timestamp': '2024-10-04T15:53:12.634000+00:00', 'pinned': False, 'mentions': [], 'mention_roles': [], 'mention_everyone': False, 'member': {'roles': ['861694343010451496'], 'premium_since': None, 'pending': False, 'nick': None, 'mute': False, 'joined_at': '2024-08-19T23:15:40.714000+00:00', 'flags': 0, 'deaf': False, 'communication_disabled_until': None, 'banner': None, 'avatar': None}, 'id': '1291790236291960985', 'flags': 0, 'embeds': [{'type': 'rich', 'description': '**A critical error has occurred!** My developer will work on fixing this as soon as possible.', 'content_scan_version': 0, 'color': 15158332}], 'edited_timestamp': None, 'content': '', 'components': [], 'channel_id': '872918217293725726', 'author': {'username': 'Midobot', 'public_flags': 0, 'id': '193431106647883776', 'global_name': None, 'discriminator': '5711', 'clan': None, 'bot': True, 'avatar_decoration_data': None, 'avatar': '7c4b43f1c7b037558f9856556e908263'}, 'attachments': [], 'guild_id': '357889493287698433'}}
2024-10-04 17:53:12 DEBUG    discord.client Dispatching event socket_event_type
2024-10-04 17:53:12 DEBUG    discord.client Dispatching event message
2024-10-04 17:53:12 DEBUG    Midobot Cluster#0 Checking XP took:                   0.00003s
2024-10-04 17:53:12 DEBUG    Midobot Cluster#0 Checking custom reaction took:      0.00002s
2024-10-04 17:53:12 DEBUG    discord.http POST https://discord.com/api/v10/channels/872918217293725726/messages with {"embeds":[{"color":15158332,"type":"rich","description":"**A critical error has occurred!** My developer will work on fixing this as soon as possible."}],"content":null,"components":[],"tts":false} has returned 200
2024-10-04 17:53:12 DEBUG    discord.http POST /channels/{channel_id}/messages has found its initial rate limit bucket hash (3df15bae86f6647dd4dfcbd5c6949480).
2024-10-04 17:53:12 DEBUG    discord.http POST https://discord.com/api/v10/channels/872918217293725726/messages has received {'type': 0, 'content': '', 'mentions': [], 'mention_roles': [], 'attachments': [], 'embeds': [{'type': 'rich', 'description': '**A critical error has occurred!** My developer will work on fixing this as soon as possible.', 'color': 15158332, 'content_scan_version': 0}], 'timestamp': '2024-10-04T15:53:12.634000+00:00', 'edited_timestamp': None, 'flags': 0, 'components': [], 'id': '1291790236291960985', 'channel_id': '872918217293725726', 'author': {'id': '193431106647883776', 'username': 'Midobot', 'avatar': '7c4b43f1c7b037558f9856556e908263', 'discriminator': '5711', 'public_flags': 0, 'flags': 0, 'bot': True, 'banner': None, 'accent_color': None, 'global_name': None, 'avatar_decoration_data': None, 'banner_color': None, 'clan': None}, 'pinned': False, 'mention_everyone': False, 'tts': False}
2024-10-04 17:53:12 ERROR    Midobot Cluster#0 Details of the last command error:
Traceback (most recent call last):
  File "/root/midobot/env/lib/python3.10/site-packages/wavelink/player.py", line 736, in connect
    await self._connection_event.wait()
  File "/usr/lib/python3.10/asyncio/locks.py", line 214, in wait
    await fut
asyncio.exceptions.CancelledError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/root/midobot/env/lib/python3.10/site-packages/wavelink/player.py", line 735, in connect
    async with async_timeout.timeout(timeout):
  File "/root/midobot/env/lib/python3.10/site-packages/async_timeout/__init__.py", line 141, in __aexit__
    self._do_exit(exc_type)
  File "/root/midobot/env/lib/python3.10/site-packages/async_timeout/__init__.py", line 228, in _do_exit
    raise asyncio.TimeoutError
asyncio.exceptions.TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/root/midobot/env/lib/python3.10/site-packages/discord/ext/commands/core.py", line 235, in wrapped
    ret = await coro(*args, **kwargs)
  File "/root/midobot/cogs/music.py", line 368, in _play
    await self.ensure_voice_client(ctx)
  File "/root/midobot/cogs/music.py", line 469, in ensure_voice_client
    await ctx.invoke(self._connect)
  File "/root/midobot/env/lib/python3.10/site-packages/discord/ext/commands/context.py", line 337, in invoke
    return await command(self, *args, **kwargs)
  File "/root/midobot/env/lib/python3.10/site-packages/discord/ext/commands/core.py", line 588, in __call__
    return await self.callback(self.cog, context, *args, **kwargs)  # type: ignore
  File "/root/midobot/cogs/music.py", line 111, in _connect
    vc: mido_utils.VoicePlayer = await channel.connect(cls=mido_utils.VoicePlayer)
  File "/root/midobot/env/lib/python3.10/site-packages/discord/abc.py", line 1966, in connect
    await voice.connect(timeout=timeout, reconnect=reconnect, self_deaf=self_deaf, self_mute=self_mute)
  File "/root/midobot/env/lib/python3.10/site-packages/wavelink/player.py", line 739, in connect
    raise ChannelTimeoutException(msg)
wavelink.exceptions.ChannelTimeoutException: Unable to connect to peynir as it exceeded the timeout of 30.0 seconds.
EvieePy commented 2 days ago

Hi, could you please try installing wavelink from github and trying again? It should install version 3.5.0

Could you then provide the 30 seconds before an 60 seconds after attempting to connect worth of logs. You can put them here: https://mystb.in