通过“在线" DiscordJS获得会员人数 [英] Getting count of members with presence 'Online' DiscordJS
本文介绍了通过“在线" DiscordJS获得会员人数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只想单独获取计数值,而不必通过循环进行卷积.我认为这非常简单,但是我所有常用的方法都给了我来自库的承诺.
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');
在这种状态下获取成员非常容易,但是我似乎不能仅获取返回的集合的 length
.
Getting the members in that presence is pretty easy, but I can't seem to just get the length
of the returned collection.
推荐答案
使用 size()
,我可以获取集合的大小.我的误解是我使用 Length
将 collection
像 array
一样对待.
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
这篇关于通过“在线" DiscordJS获得会员人数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文