问题
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