Find the total of members online/offline Discord.js

扶醉桌前 提交于 2021-01-24 13:21:30

问题


Hello I am making a server state command and I do not know how to find the total members online/offline so if someone could help me that would be awesome. :)


回答1:


client.on("message", message => {
    if (message.author.bot) return false;

    if (message.content.toLowerCase() == "stats") {
        const Embed = new discord.MessageEmbed();
        Embed.setTitle(`Server Stats`)
        // Using Collection.filter() to separate the online members from the offline members.
        Embed.addField("Online Members", message.guild.members.cache.filter(member => member.presence.status !== "offline").size);
        Embed.addField("Offline Members", message.guild.members.cache.filter(member => member.presence.status == "offline").size);
        message.channel.send(Embed);
    };
});


来源:https://stackoverflow.com/questions/63024871/find-the-total-of-members-online-offline-discord-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!