所以我试图创建一个函数,该函数可提取Members Count categorized by their Status
(online
,idle
,dnd
,offline
)...
我做了什么:
function FetchUsers(userStatus = 'online')
{
var ConnectedUsers = 0;
client.guilds.first().fetchMembers().then((guild) => {
console.log(guild.members.filter(member => member.presence.status === userStatus).size);
ConnectedUsers += guild.members.filter(member => member.presence.status === userStatus).size;
});
return ConnectedUsers;
}
我如何使用它:
console.log(FetchUsers() + " + " + FetchUsers('idle'));
输出:0 + 0
预期输出:4 + 3
实际上,console.log
输出了预期的值,但ConnectedUsers
下的idk .then
变量没有改变
编辑:
我尝试将return
移到.then之下,但显示的结果相同...
Edit2:
删除后,删除位于。之后的return
,然后显示undefined + undefined