已解决:discord.js:guild.members.cache.size不起作用

j2cgzkjk  于 2021-10-10  发布在  Java
关注(0)|答案(1)|浏览(309)

我的 guild.members.cache.size 没有工作是返回旧的成员计数(用于带有语音频道的membercount),但当我键入 console.log(guild.members.cache.size) is返回新成员计数(我认为不是缓存)。
我的代码
index.js

const functions = require('./Utils/functions.js')

client.on('guildMemberAdd', (member) => functions.updateMembers(member.guild));
client.on('guildMemberRemove', (member) => functions.updateMembers(member.guild));

functions.js

const { client } = require("../index.js");

exports.updateMembers = (guild) => {
    if((client.dbcount.get(guild.id+"m") === false) || (!client.dbcount.has(guild.id+"m"))) {
        return;
    }
    const channel = guild.channels.cache.get(client.dbcount.get(guild.id + "m"+'ch'));
    let obj;
    if(client.dbcount.has(guild.id + "m" + "obj")) {
        obj = client.dbcount.get(guild.id + "m" + "obj");
    } else {
        obj = "∞";
    }
    channel.setName('Membres: ' + guild.memberCount + "/" + obj)
    console.log(guild.memberCount);
};
ykejflvf

ykejflvf1#

client.guilds.cache.get(message.guild.id).memberCount

你可以试试这个。

相关问题