guild.voiceStates.cache force update?
When trying to get all users in a voicechannel, they are still in the cache after leaving. Is it possible to get an accurate count of users in voice channels?
12 Replies
- 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 OPI have both these intents. (and more but these are the relevant ones)
Could having more intents cause issues? I've just added a bunch without thinking about it
Voice states have
channelId
property, which is null
if the user isn't in a channelYeah sorry for the confusion. Maybe I should named it voiceChannel instead. But I will try cleaning up some of the intents and see if that helps.
Unfortunetely I need the user for what I'm doing, not only the count. Sorry for the confusion.
What you called channel is a voice state and it should be called
voiceState
or just state
. It's not a voice channel, not even a channel.
Voice states have the user info tooFrom what I can tell it is a channel. (Channel is maybe not the correct word from API standpoint, but from discord POV it's a voice channel) The channel contains a voiceState object.
No sorry, I missread. It's a guild
Yeah sorry for the confusion. But eitherway the issue is still the same. Getting the user info from here is not the issue, it's that it's cached and doesn't update correctly
It updates correctly
Did you read my reply?
Maybe it's that I'm not understanding what a VoiceState is. I have assumed that a voice channel == VoiceState. That is why I called it a channel
I don't understand the use of this channelId. If multiple users are connected to the VS, then the same channelId is just outputted once for each user
Exactly. Which I am able to, just that when someone leaves, they are still in the cache
Yes, and if the user isn't in a channel, then the channelId will be null. So after leaving the channel the user's state updates and you can filter by the channelId to get all members in the guild that are in voice channels
Then why did you ask this in your initial message?
Is it possible to get an accurate count of users in voice channels?
I see! Yeah that makes sense. I will look through this voiceChannel instead. But I don't see it in the Guild. Where is this found?
Alright, I found it in the documentation under "channels".
Sorry for the confusion guys but thanks for the help. This should do it 🙂