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 thisfor (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 theGuildMember
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
1 Answer
Reset to default 4Guild.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
版权声明:本文标题:javascript - Displaying all users in Discord channel - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741981940a2408450.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论