From 1fc86a56c23bcd37c2631a58eb91a920291c1644 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Sat, 30 Mar 2024 13:15:44 +0200 Subject: [PATCH] Make bot sticky to its configured VC --- src/client/components/MusicPlayer.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/client/components/MusicPlayer.ts b/src/client/components/MusicPlayer.ts index e4fec78..e838187 100644 --- a/src/client/components/MusicPlayer.ts +++ b/src/client/components/MusicPlayer.ts @@ -274,13 +274,21 @@ class MusicPlayer implements Initialisable if (!connectionData) return; + const config = this.#options.guilds.find(conf => conf.id === guild.id); const { connection } = connectionData; + const { me } = guild.members; + if (!me || !config) + return; try { await Promise.race([ entersState(connection, VoiceConnectionStatus.Signalling, 5_000), entersState(connection, VoiceConnectionStatus.Connecting, 5_000) ]); + // If we find ourselves here, the bot was successfully able to reconnect to a VC + // Now we check if it's the one it's meant to be in + if (me.voice.channelId !== config.voiceChannel) + this.#joinVoiceChannel(guild, config.voiceChannel, config.textOutput); } catch { @@ -288,10 +296,7 @@ class MusicPlayer implements Initialisable // this.#logger.error('Promise error:', err as Error); connection.destroy(); this.#connections.delete(guild.id); - const details = this.#options.guilds.find((conf) => conf.id === guild.id); - if (!details) - return; - this.#joinVoiceChannel(guild, details.voiceChannel, details.textOutput); + this.#joinVoiceChannel(guild, config.voiceChannel, config.textOutput); } // if (newState.status !== VoiceConnectionStatus.Disconnected) // return;