Get list of users (usernames or user IDs preferably) in a voice channel to loop through

Hello. I am trying to get a list of the users that are in a specific voice channel. I went ahead to add the GuildVoiceStates for Intents and try to pull the user names using the command below.
const voiceState = message.guild.voiceStates.cache.get(message.user.id);

console.log(voiceState.guild.members);
const voiceState = message.guild.voiceStates.cache.get(message.user.id);

console.log(voiceState.guild.members);
Whenever I try the command above, it would just give me the data about voiceState and not specifically information about the members. If anyone can help me, I would greatly appreciate it. discord.js@14.11.0 node v18.16.0
5 Replies
d.js toolkit
d.js toolkit13mo 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
Syjalo13mo ago
As you can see it's members of a guild, not a voice channel. You need
const channel = <Guild>.channels.cache.get('id');
channel.members;
const channel = <Guild>.channels.cache.get('id');
channel.members;
Iron℠
Iron℠13mo ago
I see it now. Thank you so much. And then to get the user ID, would it be something like
voiceState.members.user.id;
voiceState.members.user.id;
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Iron℠
Iron℠13mo ago
Perfect. I'll do so. So far, it seems to be working though so I'm gonna put it through a forEach loop right now and try to do what I wanna do. It worked. Everything seems to be working smoothly now. Thank you for the help.