【问题标题】:How to get member count of all members in every guild the bot is in如何获取机器人所在的每个公会中所有成员的成员数
【发布时间】:2021-11-26 20:30:52
【问题描述】:

我想在机器人的状态中显示所有公会服务器有多少成员,类似于机器人有多少服务器。

我在这里编码的是一个 10 秒的状态切换器(我猜),但我不知道如何实际获取机器人所在的所有服务器的成员数。

const Discord = require('discord.js')

module.exports = client => {
    const activities = [
    'with some code » !help',
    'with the console » !help',
    'with JavaScript » !help',
    `with ${client.guilds.cache.size} servers » !help`,
    `with ${client.guilds.cache.size.memberCount} users » !help`
    ]

    setInterval(() => {
        const randomIndex = Math.floor(Math.random() * (activities.length - 1) + 1);
        const newActivity = activities[randomIndex];
    
        client.user.setActivity(newActivity);
    }, 10000);
}

bot 显示 with undefined users » !help ,根本没有错误代码。

【问题讨论】:

    标签: discord.js


    【解决方案1】:

    Collection.size.memberCount 不是一个东西。在Client#guilds#cache 集合上使用Collection#reduce 来总结Guild#memberCount 属性使用Client#users#cache#size,它显示了机器人的用户集合中有多少缓存用户。

    【讨论】:

    • 收藏对我来说仍然有点过分,但我想现在是时候学习它们了qwq
    • 是的,你得看看收藏。
    猜你喜欢
    • 1970-01-01
    • 2021-03-14
    • 2022-06-15
    • 1970-01-01
    • 2020-11-11
    • 2020-08-15
    • 1970-01-01
    • 2018-12-29
    • 2021-11-09
    相关资源
    最近更新 更多