Realtime Member Count of Every Voice Channel

Hi, how can i get the Member Count of every Voice Channel on my Server? I'm currently using:
const voiceChannels = await guild.channels.fetch(undefined, {
cache: false,
});
const voiceChannels = await guild.channels.fetch(undefined, {
cache: false,
});
to get every Member of every Voice Channel but i'm getting not the member count in RealTime more like that the API just updates it's data every 10 - 15 Minute. How can i fix this?
11 Replies
d.js toolkit
d.js toolkit2y 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.
Syjalo
Syjalo2y ago
You don't need to fetch channels and members. You just need Guilds and GuildVoiceStates intents. Then use
<Guild>.voiceStates.cache.filter((state) => state.channelId).size;
<Guild>.voiceStates.cache.filter((state) => state.channelId).size;
Turboman3000
Turboman3000OP2y ago
WIth the cache?
Syjalo
Syjalo2y ago
Yes
Turboman3000
Turboman3000OP2y ago
Techniclly it's fixing it. But i need the Member Count with every Member and it's data, i want to track the Voice Activity from every single User. So an with your method i get the member count of every channel but not which user is in a channel and it's still not working, i'am in a Voice Channel but it just stay 0 which is the same effect -_-
Syjalo
Syjalo2y ago
Do you have required intents? You always can access <VoiceState>.member, <VoiceState>.channnel, <VoiceChannel>.members
Turboman3000
Turboman3000OP2y ago
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildPresences,
],
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildPresences,
],
Syjalo
Syjalo2y ago
Add GuildVoiceStates intent
Turboman3000
Turboman3000OP2y ago
Alright this code snippet works 🙂
for (const state of guild.voiceStates.cache.toJSON()) {
console.log(state.member?.user.username);
}
for (const state of guild.voiceStates.cache.toJSON()) {
console.log(state.member?.user.username);
}
Syjalo
Syjalo2y ago
It's better to use .values(). .toJSON() will return .entries() soon.
Want results from more Discord servers?
Add your server