0

I was creating a function that runs every second and updates a channel name to show the number of members in my server but it is just showing up as 0 members. There a no errors for the command. Here is the code:

    const guild = bot.guilds.cache.get("778322604863258686")
    setInterval(function () {
        var memberCount = guild.members.cache.filter(member => !member.user.bot).size;
        var memberCountChannel = bot.channels.cache.get("779888675915169802");
        memberCountChannel.setName(`${memberCount}`)
    }, 1000);

Image

Max
  • 3
  • 5

1 Answers1

1

Due to the new intents feature that discord implemented, you must go to the developer portal and enable the server members intent: enter image description here And, your client must be instantiated with the GUILD_MEMBERS intent:

const client = new Discord.Client({ws: {intents: ["GUILD_MEMBERS"]}});
Aplet123
  • 33,825
  • 1
  • 29
  • 55