voiceStateUpdate returns same channel IDs when disconnecting a user via right-click.

How can I detect if the bot has been disconnected by a user with client.on('voiceStateUpdate', (oldState, newState) => {})? I'm first comparing if the voiceStateUpdate even is about the bot using if (newState.guild.me.id === newState.member.id) and then trying to detect a disconnect using if (!newState.channelId) but it's not working. Any ideas? v13.8.0
6 Replies
d.js docs
d.js docs3y 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.
Meridian
MeridianOP3y ago
Currently trying to do this:
// Client events
if (newState.guild.me.id === newState.member.id) {
// Disconnect
if (!newState.channelId) {
return player.destroy()
}
}
// Client events
if (newState.guild.me.id === newState.member.id) {
// Disconnect
if (!newState.channelId) {
return player.destroy()
}
}
Jaworek
Jaworek3y ago
guild.members.me
Meridian
MeridianOP3y ago
oh youre right, guild.me doesnt exist? weird. i'm 99% sure that worked some time ago. was that a shorthand that was removed or smthn? nevermind, actually. i'm still on v13.8.0 where guild.me actually still exists
chewie
chewie3y ago
whats not working about it
Meridian
MeridianOP3y ago
apparently newState.channelId is not null, but the old channel id even tho the bot has been disconnected. i'm currently in the process of updating everything to v13.10.2 and then to v14 to see if that fixes anything. sorry to kinda necro this, but it seems you're right. i wrote a simple function that returns the difference between two objects and when i disconnect the bot manually it literally returns nothing. meaning oldState and newState are literally exactly the same. definitely seems like an API bug. any way to work around this in the meantime? is discord even aware of this yet? yup, even logging console.log(oldState.channelId, newState.channelId) returns the same channel id when disconnecting the bot. which means we currently have no way of telling if a user has disconnected, right? EDIT: seems like its only when disconnecting another user. if i'm disconnecting myself it works as intended gladly. i added the code and tried connecting the bot via a command and then disconnecting it using the right-click option. i get a packet when connecting as expected, but when disconnecting the bot the packet still has the channel id in the field channel_id alright, thanks for your help! closing this since its not a d.js issue.
Want results from more Discord servers?
Add your server