From 57f3d9c481f6bb6196bfb36f4f2c5cb84559964f Mon Sep 17 00:00:00 2001 From: NoLogicAlan Date: Mon, 4 May 2026 03:46:23 +0300 Subject: [PATCH] test --- index.mjs | 8 +++++++- src/Player.mjs | 22 +++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/index.mjs b/index.mjs index 2749145..a3074c7 100644 --- a/index.mjs +++ b/index.mjs @@ -304,7 +304,8 @@ class Remix { const isTransient = e.message?.includes("engine is closed") || e.message?.includes("MediaPlayer after retry") || e.message?.includes("LiveKit connection timeout") || - e.message?.includes("LiveKit failed"); + e.message?.includes("LiveKit failed") || + e.message?.includes("No room available"); const shouldRetry = isTransient && !recoveryData?.queue?.length ? (() => { try { @@ -877,6 +878,11 @@ class Remix { if (existingPlayer && cleanId !== cleanOld) { this.players.playerMap.delete(cleanOld); this.players.playerMap.set(cleanId, existingPlayer); + // CRITICAL: also update the player's own _channelId so that + // _recoverConnection, _is247Enabled, and _hasHumansInChannel + // all use the correct channel. Without this they keep referencing + // the old channel even after the bot has moved. + existingPlayer._channelId = cleanId; logger.voice247(`[247] Re-keyed playerMap ${cleanOld} → ${cleanId}`); } diff --git a/src/Player.mjs b/src/Player.mjs index 16b63ac..6fc3142 100644 --- a/src/Player.mjs +++ b/src/Player.mjs @@ -407,13 +407,25 @@ export default class Player extends EventEmitter { if (!set?.get) return false; const raw = set.get("stay_247"); if (!raw || raw === "none") return false; + const mode = set.get("stay_247_mode") ?? "auto"; + if (mode !== "on" && mode !== "auto") return false; + const channels = Array.isArray(raw) ? raw.map(id => String(id).replace(/\D/g, "")).filter(Boolean) : [String(raw).replace(/\D/g, "")]; const currentChannel = String(this._channelId).replace(/\D/g, ""); - if (!channels.includes(currentChannel)) return false; - const mode = set.get("stay_247_mode") ?? "auto"; - return mode === "on" || mode === "auto"; + + // Primary check: current channel is in the 247 list. + if (channels.includes(currentChannel)) return true; + + // Fallback: if the player is mid-recovery or mid-join, the bot may + // temporarily be in a transit channel (e.g. "move") that isn't in the + // 247 list yet. If the guild has ANY 247 channels configured and active, + // treat the player as 247 to prevent premature inactivity/alone timers + // from firing while the player is still reconnecting to the right channel. + if ((this._isRecovering || this._isJoining) && channels.length > 0) return true; + + return false; }; if (this.settingsMgr?.getServer) return checkSettings(this.settingsMgr.getServer(this._guildId)); @@ -1098,6 +1110,10 @@ export default class Player extends EventEmitter { logger.mediaplayer("[Player] Proceeding to create MediaPlayer (room confirmed alive)"); } else { + // connection.room is null — this happens when joinVoiceChannel returns + // a stale/recycled connection object before the LiveKit room is assigned, + // usually due to a concurrent join race or a channel that no longer has + // an active room. Treat it as transient so the retry loop handles it. throw new Error("No room available after joinVoiceChannel"); }