VoiceChannel members is always 0

My bot has all the intents enabled in the Dev Portal and programatically (including GuildVoiceStates and GuildMembers intents) In VoiceStateUpdate event I need a total members currently in the voice chat I tried to force fetch all channels and/or force fetch individually and still not working... I am testing when I have ppl in one of the VCs
const channels = guild.channels.cache
const voiceChannels = channels.filter(channel => channel.type === ChannelType.GuildVoice
) ;

await guild.members.fetch();

voiceChannels.forEach(async channel => {
const latestChannel = await guild.channels.fetch(channel.id) as unknown as VoiceChannel;
// latestChannel.members is always Collection 0 with no members in it
}
});
const channels = guild.channels.cache
const voiceChannels = channels.filter(channel => channel.type === ChannelType.GuildVoice
) ;

await guild.members.fetch();

voiceChannels.forEach(async channel => {
const latestChannel = await guild.channels.fetch(channel.id) as unknown as VoiceChannel;
// latestChannel.members is always Collection 0 with no members in it
}
});
No description
17 Replies
d.js toolkit
d.js toolkit5mo 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!
Nothing-Man
Nothing-Man5mo ago
my-bot@1.0.0 /Users/andriy/Documents/projects/discord-bot ├─┬ discord.js-rate-limiter@1.3.2 │ └── discord.js@14.14.1 deduped └── discord.js@14.14.1 Node: v16.20.1
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Nothing-Man
Nothing-Man5mo ago
@gwapes updated the code with fetch members and fetch channel individually, still Collection(0) [Map] {} couldnt find way to force fetch members though these are the options:
export interface FetchMembersOptions {
user?: UserResolvable | UserResolvable[];
query?: string;
limit?: number;
withPresences?: boolean;
time?: number;
nonce?: string;
}
export interface FetchMembersOptions {
user?: UserResolvable | UserResolvable[];
query?: string;
limit?: number;
withPresences?: boolean;
time?: number;
nonce?: string;
}
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Nothing-Man
Nothing-Man5mo ago
yes thats what I did (see updated code) still collection is 0
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Nothing-Man
Nothing-Man5mo ago
const channels = guild.channels.cache
const voiceChannels = channels.filter(channel => channel.type === ChannelType.GuildVoice
) ;

await guild.members.fetch();

voiceChannels.forEach(async channel => {
// latestChannel.members is always Collection 0 with no members in it
}
});
const channels = guild.channels.cache
const voiceChannels = channels.filter(channel => channel.type === ChannelType.GuildVoice
) ;

await guild.members.fetch();

voiceChannels.forEach(async channel => {
// latestChannel.members is always Collection 0 with no members in it
}
});
^ removed fetching the channel, still Collection(0) [Map] {}
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Nothing-Man
Nothing-Man5mo ago
Client constructor 🚀 ~ start ~ Config.client.intents: [ 'Guilds', 'GuildMembers', 'GuildModeration', 'GuildBans', 'GuildEmojisAndStickers', 'GuildIntegrations', 'GuildWebhooks', 'GuildInvites', 'GuildVoiceStates', 'GuildPresences', 'GuildMessages', 'GuildMessageReactions', 'GuildMessageTyping', 'DirectMessages', 'DirectMessageReactions', 'DirectMessageTyping', 'MessageContent', 'GuildScheduledEvents', 'AutoModerationConfiguration', 'AutoModerationExecution' ]
No description
Nothing-Man
Nothing-Man5mo ago
the function
No description
Nothing-Man
Nothing-Man5mo ago
No description
No description
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Nothing-Man
Nothing-Man5mo ago
@gwapes YES! I removed the cache and it works! Thank you so mmuch! you made my day! I was super tilted
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
Nothing-Man
Nothing-Man5mo ago
took the bot boilerplate and it had this
souji
souji5mo ago
in case someone else finds this and wonders why the cache is necessary here: - voice states are received from the initial guild payloads when the bot identifies with the gateway or joins a new server - the cache is updated based on received voice state update events - there is no endpoint to fetch the current members of a voice channel