Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

117
Visualizações
Filter out bots from member count in client status

I want to make my bot activity say "Watching + Member Count (not include bots)".

I did some steps, here is my code:

client.once('ready', () => { 
        setInterval(() => {
          targetGuild = client.guilds.cache.get('My Guild ID Here')
          client.user.setPresence({ 
            activities: [{ name: `${targetGuild.memberCount} Users`, type: 'WATCHING' }], 
            status: 'online'
            });
        }, 1000 * 60 * 5);
    
    });

The thing that I need is to set a filter that it calculate members only, not bots.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Use GuildMemberManager#fetch() to fetch all members, then use Collection#partition() to split the member collection into bots and humans. Use humans.size to display the user count as you intend. You can also Collection#filter() to filter the member collection to just the humans, however I use partition in this example to have access to both parties in one function call.

client.once('ready', async() => { 
   targetGuild = client.guilds.cache.get('My Guild ID Here');
   try {
      const [bots, humans] = (await targetGuild.members.fetch())
         .partition(member => member.user.bot);
      setInterval(() => {
         client.user.setPresence({ 
            activities: [
               { 
                  name: `${humans.size} Users`, 
                  type: 'WATCHING' 
               }
            ], 
            status: 'online'
         });
      }, 1000 * 60 * 5);
   } catch (err) {
      console.error(err);
   }
});
about 4 years ago · Juan Pablo Isaza Relatório

0

In discord.js v13 the member counting with bot filtering should look like this:

   setInterval(() => {
        const guild = client.guilds.cache.get('GUILD_ID');
          let humanMembers = guild.members.cache.filter(
            (user) => !user.user.bot
          );
          const channel = guild.channels.cache.get('CHANNEL_ID');
          channel.setName(`👤Member Count Test: ${humanMembers.size.toString()}`);
        }, 60000);
});

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda