Skip to content
This repository was archived by the owner on Apr 5, 2025. It is now read-only.

Commit 2a41e1b

Browse files
authored
Fix player destroyed after voice moved
When the bot moves channels, the player was being destroyed because the disconnect wait did not account for the brief period between disconnect and reconnect. This commit modifies `_disconnected_wait` to wait for the _reconnecting event and then verifies the current voice state via `guild.me.voice.channel`. If a valid channel is detected, the connection is restored without calling `_destroy()`. This prevents accidental player deletion during channel moves.
1 parent 23f28e1 commit 2a41e1b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

wavelink/player.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,23 @@ async def _disconnected_wait(self, code: int, by_remote: bool) -> None:
178178
return
179179

180180
self._connected = False
181+
182+
# Wait for the reconnect event to be set.
181183
await self._reconnecting.wait()
182184

185+
# Verify the voice state to determine if a reconnect has occurred.
186+
if self.guild and self.guild.me and self.guild.me.voice and self.guild.me.voice.channel:
187+
# If the bot is connected to a new channel, mark as connected.
188+
self._connected = True
189+
self._connection_event.set()
190+
logger.debug("Reconnected during move; skipping _destroy() in _disconnected_wait.")
191+
return
192+
183193
if self._connected:
184194
return
185195

186196
await self._destroy()
187-
197+
188198
def _inactivity_task_callback(self, task: asyncio.Task[bool]) -> None:
189199
cancelled: bool = False
190200

0 commit comments

Comments
 (0)