what does joinVoiceChannel return when there's already an active voice connection?

so the guide says
If you try to call joinVoiceChannel on another channel in the same guild in which there is already an active voice connection, the existing voice connection switches over to the new channel.
does it return the same VoiceConnection object as before changing channels (therefore, it already has event listeners attached, if any) or is it a new VoiceConnection with the old one destroyed?
3 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
duck
duck2y ago
I believe it's the same VoiceConnection object
Nutchapol
NutchapolOP2y ago
i've tested just to be sure but yes, it's the same object thanks i ran
function connectToVC(channelId) {
console.log(`connecting to vc ${channelId}`)
const voiceConnection = joinVoiceChannel({
guildId: targetGuild.id,
channelId,
adapterCreator: targetGuild.voiceAdapterCreator,
})
// assume i have targetGuild fetched somewhere else

if (connectionExisted) {
return
}

voiceConnection.subscribe(audioPlayer)
voiceConnection.on('stateChange', (oldState, newState) => {
console.log(`voice connection ${oldState.status} -> ${newState.status}`)
})
console.log(`voice connection ${voiceConnection._state.status}`)
console.log(voiceConnection)
}

connectToVC(123123132123)
connectToVC(456456465456)
connectToVC(123123132123)
connectToVC(456456465456)
connectToVC(123123132123)
connectToVC(456456465456)
function connectToVC(channelId) {
console.log(`connecting to vc ${channelId}`)
const voiceConnection = joinVoiceChannel({
guildId: targetGuild.id,
channelId,
adapterCreator: targetGuild.voiceAdapterCreator,
})
// assume i have targetGuild fetched somewhere else

if (connectionExisted) {
return
}

voiceConnection.subscribe(audioPlayer)
voiceConnection.on('stateChange', (oldState, newState) => {
console.log(`voice connection ${oldState.status} -> ${newState.status}`)
})
console.log(`voice connection ${voiceConnection._state.status}`)
console.log(voiceConnection)
}

connectToVC(123123132123)
connectToVC(456456465456)
connectToVC(123123132123)
connectToVC(456456465456)
connectToVC(123123132123)
connectToVC(456456465456)
then saw that there's more listeners for stateChange in voiceConnection's list of listeners
Want results from more Discord servers?
Add your server