Problem with reconnecting to voice channel and resuming of audio.

My internet connection is not stable and when lag spike is appear, i catch the disconnect from Websocket (i listen ShardDisconnect, ShardResume events). So i want to make "reconnect" when ShardResume is triggered. This code i use when iterate through all existing players. But i am stucking in signalling state and i dont know why
const voice = Audio.distube.voices.get(player.textChannel.guild)
const connection = getVoiceConnection(player.textChannel.guild.id, player.textChannel.guild.client.user.id)
if (!voice) return
loggerSend(`Status: ${connection?.state.status}`)
if (!connection) return

connection.once('stateChange', (oldState, newState) => {
loggerSend(`OldState: ${oldState.status}, NewState: ${newState.status}`)
if (!connection) return
if (newState.status === VoiceConnectionStatus.Ready) {
connection.configureNetworking()
loggerSend(connection.state.status)
const VoicePlayer = voice.audioPlayer

loggerSend("subscribe audioplayer")
connection.subscribe(VoicePlayer)

const audioRes = voice.audioResource
if (audioRes){
VoicePlayer.unpause()
loggerSend("player audioResource")
VoicePlayer.play(audioRes)
}
}
})

setTimeout(() => {
if (voice.channel.joinable){
loggerSend("Try to rejoin")
connection?.rejoin()
}

// connection = joinVoiceChannel({
// channelId: voice.channel.id,
// guildId: player.textChannel.guild.id,
// adapterCreator: player.textChannel.guild.voiceAdapterCreator
// })

loggerSend(`Status After Join: ${connection?.state.status}, Channel ${voice.channel.id}`)
}, 2000)
const voice = Audio.distube.voices.get(player.textChannel.guild)
const connection = getVoiceConnection(player.textChannel.guild.id, player.textChannel.guild.client.user.id)
if (!voice) return
loggerSend(`Status: ${connection?.state.status}`)
if (!connection) return

connection.once('stateChange', (oldState, newState) => {
loggerSend(`OldState: ${oldState.status}, NewState: ${newState.status}`)
if (!connection) return
if (newState.status === VoiceConnectionStatus.Ready) {
connection.configureNetworking()
loggerSend(connection.state.status)
const VoicePlayer = voice.audioPlayer

loggerSend("subscribe audioplayer")
connection.subscribe(VoicePlayer)

const audioRes = voice.audioResource
if (audioRes){
VoicePlayer.unpause()
loggerSend("player audioResource")
VoicePlayer.play(audioRes)
}
}
})

setTimeout(() => {
if (voice.channel.joinable){
loggerSend("Try to rejoin")
connection?.rejoin()
}

// connection = joinVoiceChannel({
// channelId: voice.channel.id,
// guildId: player.textChannel.guild.id,
// adapterCreator: player.textChannel.guild.voiceAdapterCreator
// })

loggerSend(`Status After Join: ${connection?.state.status}, Channel ${voice.channel.id}`)
}, 2000)
2 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
AlexInCube
AlexInCubeOP2y ago
Want results from more Discord servers?
Add your server