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 toolkit10mo 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-ManOP10mo ago
[email protected] /Users/andriy/Documents/projects/discord-bot ├─┬ [email protected] │ └── [email protected] deduped └── [email protected] Node: v16.20.1
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Nothing-Man
Nothing-ManOP10mo 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 User10mo ago
Message Not Public
Sign In & Join Server To View
Nothing-Man
Nothing-ManOP10mo ago
yes thats what I did (see updated code) still collection is 0
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Nothing-Man
Nothing-ManOP10mo 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 User10mo ago
Message Not Public
Sign In & Join Server To View
Nothing-Man
Nothing-ManOP10mo 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-ManOP10mo ago
the function
No description
Nothing-Man
Nothing-ManOP10mo ago
No description
No description
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Nothing-Man
Nothing-ManOP10mo 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 User10mo ago
Message Not Public
Sign In & Join Server To View
Nothing-Man
Nothing-ManOP10mo ago
took the bot boilerplate and it had this
souji
souji10mo 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
Want results from more Discord servers?
Add your server