'Get the number of bots in a server

I'm making a public member count for my server, which will be displayed in the name of a locked voice channel on top of the channel list.

Though, to make the count even more accurate, I would like not to include the bots into the member count. I assume the best way to do that would be to subtract the number of bots from the total number of members in the server.

The thing is, I don't know how to get the number of bots in a server (only the total number of members).

Thank you all in advance :D



Solution 1:[1]

Notice you will need to turn on member intents for your bot for this to work:

@client.command()
async def bot_count(ctx):
    members = ctx.author.guild.members
    bot_count = 0
    for i in members:
        member = i.bot
        if member == True:
            bot_count += 1

    await ctx.send(f"Server has {bot_count} bots!")

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 RiveN