Unexpected behavior of client.on(Events.VoiceStateUpdate)

I need to check which users are in the channel and which are not after someone leaves. When I subscribe to Events.VoiceStateUpdate and try to console.log the users that are in the channel
client.on(Events.VoiceStateUpdate, (oldState, newState) => {
console.log(oldState.channel?.members.map((m) => m.id));
console.log(newState.channel?.members.map((m) => m.id));
}
client.on(Events.VoiceStateUpdate, (oldState, newState) => {
console.log(oldState.channel?.members.map((m) => m.id));
console.log(newState.channel?.members.map((m) => m.id));
}
it logs
['1020597576728334398']
undefined
['1020597576728334398']
undefined
Although I was expecting to see this
['1020597576728334398', '546703392081313793']
['1020597576728334398']
['1020597576728334398', '546703392081313793']
['1020597576728334398']
Can you please tell me why this is happening?
4 Replies
d.js toolkit
d.js toolkit2w ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Guleb
Guleb2w ago
My discord.js is 14.15.3 and my node.js is v20.9.0
NyR
NyR2w ago
Can you log <State>.constructor.name for both oldState and newState?
Guleb
Guleb2w ago
it is
VoiceState
VoiceState
VoiceState
VoiceState
The situation is like this, there is a bot and 1 user in the channel, when user leaves, I expected to see this
['1020597576728334398', '546703392081313793']
['1020597576728334398']
['1020597576728334398', '546703392081313793']
['1020597576728334398']
1020597576728334398 - is a bot id Okay, thanks a lot, I thought newState.member was the bot itself