fix(voice): resolve voice channel detection after bot reboot

- Move voice state population outside settings conditional in GuildCreate
  (now runs on every gateway resume, not just new guild joins)
- Make checkVoiceChannels() async with Fluxer API fallback
  (fetches member voice state directly when cache is empty after reboot)
- Fix PlayerManager client reference passing
- Update all callers to properly await checkVoiceChannels()
- Fix leave command to work without requiring user in voice channel

Fixes issue where bot couldn't detect users already in voice channels
immediately after a reboot due to empty voice state cache.
This commit is contained in:
NoLogicAlan committed 2026-04-16 23:41:25 +03:00
1 parent b1e9964a56
commit 73c290e59c
7 files changed
+180 -403

No files matched your search

+26 -17
View File
@@ -16,26 +16,35 @@ function embed(desc) {
export async function run(msg) {
const guildId = msg.channel?.guild?.id ?? msg.message?.guildId;
const userChannelId = this.players.checkVoiceChannels(msg);
if (!userChannelId) return msg.replyEmbed(embed("⚠️ Please join a voice channel first."));
// Get all players in this guild
const guildPlayers = [...this.players.playerMap.entries()]
.filter(([chId, p]) => p._guildId === guildId);
const cid = String(userChannelId).replace(/\D/g, "");
if (!this.players.playerMap.has(cid)) {
const guildChannels = [...this.players.playerMap.entries()]
.filter(([chId, p]) => p._guildId === guildId)
.map(([chId]) => `<#${chId}>`);
if (guildChannels.length === 0) return msg.replyEmbed(embed("I'm not in a voice channel."));
if (guildChannels.length === 1) return msg.replyEmbed(embed(`⚠️ Please join ${guildChannels[0]} to use this command.`));
return msg.replyEmbed(embed(
`⚠️ I'm playing in multiple channels! Please join one of them:\n` +
guildChannels.map(c => `• ${c}`).join("\n")
));
if (guildPlayers.length === 0) {
return msg.replyEmbed(embed("❌ I'm not in a voice channel in this server."));
}
let cid;
// Try to find the channel the user is in (optional, for convenience)
const userChannelId = await this.players.checkVoiceChannels(msg);
if (userChannelId && guildPlayers.some(([chId]) => chId === userChannelId)) {
// User is in a channel where the bot is playing - use that one
cid = userChannelId;
} else if (guildPlayers.length === 1) {
// Only one player in guild - use that one
cid = guildPlayers[0][0];
} else {
// Multiple channels - use the first one found
// Or you could implement a selection menu here
cid = guildPlayers[0][0];
}
cid = String(cid).replace(/\D/g, "");
const player = this.players.playerMap.get(cid);
if (!player?.connection) return msg.replyEmbed(embed("Player not initialized."));
if (!player?.connection) return msg.replyEmbed(embed("❌ Player not initialized."));
const set = this.getSettings(msg);
const raw = set?.get("stay_247");
@@ -68,4 +77,4 @@ export async function run(msg) {
} else {
await this.leaveChannel(cid, guildId, msg);
}
}
}