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 toolkit14mo 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.
Turboman3000
Turboman300014mo ago
node@v18.15.0 discord.js@14.11.0
Syjalo
Syjalo14mo 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
Turboman300014mo ago
WIth the cache?
Syjalo
Syjalo14mo ago
Yes
Turboman3000
Turboman300014mo 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
Syjalo14mo ago
Do you have required intents? You always can access <VoiceState>.member, <VoiceState>.channnel, <VoiceChannel>.members
Turboman3000
Turboman300014mo 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
Syjalo14mo ago
Add GuildVoiceStates intent
Turboman3000
Turboman300014mo 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
Syjalo14mo ago
It's better to use .values(). .toJSON() will return .entries() soon.