Make bot sticky to its configured VC
This commit is contained in:
parent
6a6be77dbd
commit
1fc86a56c2
@ -274,13 +274,21 @@ class MusicPlayer implements Initialisable
|
|||||||
if (!connectionData)
|
if (!connectionData)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
const config = this.#options.guilds.find(conf => conf.id === guild.id);
|
||||||
const { connection } = connectionData;
|
const { connection } = connectionData;
|
||||||
|
const { me } = guild.members;
|
||||||
|
if (!me || !config)
|
||||||
|
return;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Promise.race([
|
await Promise.race([
|
||||||
entersState(connection, VoiceConnectionStatus.Signalling, 5_000),
|
entersState(connection, VoiceConnectionStatus.Signalling, 5_000),
|
||||||
entersState(connection, VoiceConnectionStatus.Connecting, 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
|
catch
|
||||||
{
|
{
|
||||||
@ -288,10 +296,7 @@ class MusicPlayer implements Initialisable
|
|||||||
// this.#logger.error('Promise error:', err as Error);
|
// this.#logger.error('Promise error:', err as Error);
|
||||||
connection.destroy();
|
connection.destroy();
|
||||||
this.#connections.delete(guild.id);
|
this.#connections.delete(guild.id);
|
||||||
const details = this.#options.guilds.find((conf) => conf.id === guild.id);
|
this.#joinVoiceChannel(guild, config.voiceChannel, config.textOutput);
|
||||||
if (!details)
|
|
||||||
return;
|
|
||||||
this.#joinVoiceChannel(guild, details.voiceChannel, details.textOutput);
|
|
||||||
}
|
}
|
||||||
// if (newState.status !== VoiceConnectionStatus.Disconnected)
|
// if (newState.status !== VoiceConnectionStatus.Disconnected)
|
||||||
// return;
|
// return;
|
||||||
|
Loading…
Reference in New Issue
Block a user