Displaying all users in Discord channel

Viewed 15199

Right now I am working on a Discord bot and am attempting to list all users that are currently connected to the "general" voice channel.

My main issue right now is that my code is able to realize the number of people in the voice channel, but all of the "member" objects are undefined. This is both the console outputs and code. I have searched everywhere and can't seem to find anything.

This is the output from the console, the three "undefined" logs are the current users in the voice channel:

enter image description here

This is the code I have written:

enter image description here

For convience, this is also the code...

var chan = bot.channels['363589387411259396'];
var mems = chan.members;
for (var x in mems) {
  console.log(x.userID);
}
return 'ANYTHING';

Any inputs helps, thanks!

1 Answers

Guild.members returns a Collection<Snowflake, GuildMember> object, where Snowflake is the GuildMember's ID.

Your main issue is this:
userID property does not exist. What you should be looking for is GuildMember.id or simply printing out the Snowflake.
(Since it does not exist, printing out GuildMember.userID would result in printing out undefined)

Also, you can do your loop as what Venkata mentioned in the comments.

Related