0

So I have used this code for counting my members on my discord server but then it suddenly stopped. I used the same code for a month or more and now I don't understand the problem. I have no errors or anything it just no longer counts the members when they join or leave.

let serverStats = {
    ServerId: '763432307863322645',
    totalUsersID: '764267842413264926',
    memberCountID: '764267939196043294',
    botCountID: '764268032637796402'
};


client.on('guildMemberAdd', member =>{

    if (member.guild.id !== serverStats.ServerId) return;

    client.channels.cache.get(serverStats.totalUsersID).setName(`Total Users: ${member.guild.memberCount}`);
    client.channels.cache.get(serverStats.memberCountID).setName(`Members: ${member.guild.members.cache.filter(m => !m.user.bot).size}`);
    client.channels.cache.get(serverStats.botCountID).setName(`Bots: ${member.guild.members.cache.filter(m => m.user.bot).size}`);

});

client.on('guildMemberRemove', member =>{

    if (member.guild.id !== serverStats.ServerId) return;

    client.channels.cache.get(serverStats.totalUsersID).setName(`Total Users: ${member.guild.memberCount}`);
    client.channels.cache.get(serverStats.memberCountID).setName(`Members: ${member.guild.members.cache.filter(m => !m.user.bot).size}`);
    client.channels.cache.get(serverStats.botCountID).setName(`Bots: ${member.guild.members.cache.filter(m => m.user.bot).size}`);

});
  • Have you tried logging `client.channels.cache.get(serverStats.[...])` inside the events to see if they are properly populated? – Technoh Nov 03 '20 at 21:26
  • If it worked for a month or more, and it "suddenly stopped", without you changing anything at all, not one little thing no matter how insignificant you may think the change was, I'm not sure what you expect someone else to do - the only thing that looks out of place is `.size` - but that would've always been wrong (if it is wrong) anyway – Jaromanda X Nov 03 '20 at 21:29
  • 1
    Does this answer your question? [None of my discord.js guildmember events are emitting, my user caches are basically empty, and my functions are timing out?](https://stackoverflow.com/questions/64559390/none-of-my-discord-js-guildmember-events-are-emitting-my-user-caches-are-basica) – Lioness100 Nov 03 '20 at 21:36

1 Answers1

0

Have you tried using the property Guild#memberCount ? It is supposed to return the number of members in your guild, so should meet your needs.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Rak Laptudirm
  • 174
  • 2
  • 13