Get every User in a Voice Channel with REST/CORE

How do I do this?
7 Replies
d.js toolkit
d.js toolkit16mo 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!
duck
duck16mo ago
there isn't actually an endpoint for requesting voice states you'd need to receive and store the voice states from the GuildCreate event and track further updates from the VoiceStateUpdate event then you filter by <GatewayVoiceState>.channel_id if you're using /core, you'll want to reference and familiarize yourself with the discord api docs directly
progamersischu
progamersischuOP16mo ago
How is d.js then doing it. Also saving it somewhere to collect is as data later again? I mean there is a function/way to get every user in a voice channel channel.members
duck
duck16mo ago
yes, it's caching it in <Guild>.voiceStates.cache <VoiceChannel>.members exists in discord.js and is a getter that just filters cached GuildMembers based on their voice states this is effectively what you'd want to do
then you filter by <GatewayVoiceState>.channel_id
progamersischu
progamersischuOP16mo ago
Then I am confused why I can retrieve users from the different channels. Even if the bot was restarted and the cache cleared.
duck
duck16mo ago
Then I am confused why I can retrieve users from the different channels.
I'm not sure why this would be confusing you just filter by different channel ids
Even if the bot was restarted and the cache cleared.
in discord.js, <VoiceChannel>.members relies on the VoiceState and GuildMember caches GuildMembers are not cached on ready, but you may be fetching all members at some point in your code for voice states, the GuildCreate event is emitted for each guild a given shard should be handling after connecting to the gateway, so VoiceStates are cached on ready again, if you're using /core, you'll want to reference and familiarize yourself with the discord api docs directly feel free to check out discord.js's source if you feel to need to confirm how discord.js is handling this
progamersischu
progamersischuOP16mo ago
Thx I only use core to use discords data to use it from my bot on another appliaction/website etc. That explains a lot. I thought the cache works like that on restart it gets cleared. But if it uses the other events to retrieve data for the VoiceState then it makes more sense to me
Want results from more Discord servers?
Add your server