最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Getting count of members with presence 'Online' DiscordJS - Stack Overflow

programmeradmin0浏览0评论

I just want to get the count value alone without having to convolute with a loop. I believe this to be extremely simple, but all my usual approaches are giving me promise rejections from the library.

// Get our server
const guild = bot.guilds.get('388093207575134208');

// Get our stats channels
const totalUsers = bot.channels.get('470358845751951361');
const onlineUsers = bot.channels.get('470366354222874665');
const codeMonkeys = bot.channels.get('470358906225295391');


var userCount = guild.memberCount;
var onlineCount = guild.members.filter(m => m.presence.status === 'online');

Getting the members in that presence is pretty easy, but I can't seem to just get the length of the returned collection.

I just want to get the count value alone without having to convolute with a loop. I believe this to be extremely simple, but all my usual approaches are giving me promise rejections from the library.

// Get our server
const guild = bot.guilds.get('388093207575134208');

// Get our stats channels
const totalUsers = bot.channels.get('470358845751951361');
const onlineUsers = bot.channels.get('470366354222874665');
const codeMonkeys = bot.channels.get('470358906225295391');


var userCount = guild.memberCount;
var onlineCount = guild.members.filter(m => m.presence.status === 'online');

Getting the members in that presence is pretty easy, but I can't seem to just get the length of the returned collection.

Share Improve this question asked Sep 28, 2018 at 23:38 CodeSpentCodeSpent 1,9245 gold badges27 silver badges50 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 1

Using size() I was able to get the size of the collection. My misconception was that I was treating a collection like an array by using Length.

// Get our server
const guild = bot.guilds.get('388093207575134208');

// Get our stats channels
const totalUsers = bot.channels.get('470358845751951361');
const onlineUsers = bot.channels.get('470366354222874665');
const codeMonkeys = bot.channels.get('470358906225295391');


var userCount = guild.memberCount;
var onlineCount = guild.members.filter(m => m.presence.status === 'online').size
发布评论

评论列表(0)

  1. 暂无评论