admin管理员组

文章数量:1315225

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:

This is the code I have written:

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!

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:

This is the code I have written:

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!

Share Improve this question edited Oct 1, 2017 at 0:01 ibrahim mahrir 31.7k5 gold badges49 silver badges77 bronze badges asked Sep 30, 2017 at 22:59 T. SmithT. Smith 511 gold badge1 silver badge2 bronze badges 6
  • Could you please provide the link to API? – Venkata Raju Commented Sep 30, 2017 at 23:54
  • Of course. discord.js/#/docs/main/stable/class/Client <-- this is the Client object documentation discord.js/#/docs/main/stable/class/Channel <-- this is the Channel object documentation – T. Smith Commented Oct 1, 2017 at 3:41
  • members is a Collection<Snowflake, GuildMember> which extends Map so you should be able to iterate through the key values like this for (let [snowflake, guildMember] of mems) { console.log('snowflake: ' + snowflake); console.log('id: ' + guildMember.id); console.log('user id: ' + guildMember.user.id); } – Venkata Raju Commented Oct 1, 2017 at 5:26
  • BTW i don't see any userID property in search not sure where you got that from. All the GuildMember properties and methods are available here – Venkata Raju Commented Oct 1, 2017 at 5:29
  • I see. I'll also test that out, thanks! – T. Smith Commented Oct 2, 2017 at 2:39
 |  Show 1 more ment

1 Answer 1

Reset to default 4

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 ments.

本文标签: javascriptDisplaying all users in Discord channelStack Overflow