Add automatic reconnection logic to voice connection
This commit is contained in:
parent
e74fc3fd99
commit
1b5579fdde
17
src/bot.js
17
src/bot.js
|
@ -62,6 +62,23 @@ function JoinChannel(channel, track, volume) {
|
||||||
adapterCreator: channel.guild.voiceAdapterCreator,
|
adapterCreator: channel.guild.voiceAdapterCreator,
|
||||||
selfDeaf: true
|
selfDeaf: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connection.on(dVC.VoiceConnectionStatus.Disconnected, async () => {
|
||||||
|
let attemptReconnect = true;
|
||||||
|
while (attemptReconnect) {
|
||||||
|
try {
|
||||||
|
console.log("Disconnected. Attempting to reconnect...");
|
||||||
|
await Promise.race([
|
||||||
|
entersState(connection, dVC.VoiceConnectionStatus.Signalling, 5_000),
|
||||||
|
entersState(connection, dVC.VoiceConnectionStatus.Connecting, 5_000),
|
||||||
|
]);
|
||||||
|
console.log("Reconnected successfully.");
|
||||||
|
attemptReconnect = false;
|
||||||
|
} catch (error) {
|
||||||
|
console.log("Reconnection attempt failed. Retrying...");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const resource = dVC.createAudioResource(track, {inlineVolume: true, silencePaddingFrames: 5});
|
const resource = dVC.createAudioResource(track, {inlineVolume: true, silencePaddingFrames: 5});
|
||||||
const player = dVC.createAudioPlayer();
|
const player = dVC.createAudioPlayer();
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
{
|
{
|
||||||
"token": "Insert-token-here"
|
"token": "Insert-Token-Here"
|
||||||
}
|
}
|
Loading…
Reference in a new issue