'How to make my Discord.js bot that leaves servers below a certain member count

I am making a discord.js bot and trying to get it verified! I want to make it so when you add it to a server and it has below 35 members it leaves it. This is so when I get it verified it doesn't think I am inorganically growing the bot. Is this possible?



Solution 1:[1]

DJS Documentation

In order to achieve this, you need to bring together different attributes and methods.

Client: GuildCreate Event

Guild: MemberCount

Guild: Leave

Sample

Start GuildCreate Event => 
    if (guild has less than 35 members) do 
         leave guild
    endif
endfunction
client.on('guildCreate', (guild) => {
    if (guild.memberCount < 35) {
        guild.leave();
    }
})

Solution 2:[2]

So you can do this using a eval command on which I have done before the permissions you just need is the members intent and you can make it leave servers under the member count

client.guilds.cache.forEach(guild => {
    const memberCount = guild.members.cache.filter(member => !member.user.bot).size

// This filters out bots and only counts true members

    if (memberCount < 35) {
        guild.leave()
        console.log(`Left the ${guild.name} guild because they only had ${memberCount} members!`)
    }
})

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ThatsLiamS
Solution 2 strongavenger07