Member Counter Discord Bot

Test this app for free
148
import os
import discord
from discord.ext import commands
from tabulate import tabulate

# Enable all intents and specifically enable the 'members' intent
intents = discord.Intents.all()
intents.members = True

# Get the bot token from environment variables
bot_token = os.environ['BOT_TOKEN']

# Create a new bot instance with the specified command prefix and intents
bot = commands.Bot(command_prefix='!', intents=intents)

# Event that runs when the bot has connected to the server
@bot.event
async def on_ready():
    print(f'We have logged in as {bot.user}')

# Command that counts the total number of members, bots and members excluding bots
@bot.command()
async def member_count(ctx):
Get full code

Created: | Last Updated:

This template is, for a Discord bot that calculates the number of members, number of bots and total number of non bot members in a server. It displays a message with the member count in a table format when triggered by the !member_count command in any channel. Additionally it tracks the member count for each role. Presents this information in a table format when triggered by the !member_count_role command. The bot needs permissions and intents to work.

Introduction to the Member Counter Discord Bot Template

Welcome to the Member Counter Discord Bot template! This template offers you a made bot that can tally up the overall number of members, bots and non bot members within a Discord server. It also keeps track of member counts per role. This bot is ideal for server admins looking to monitor their communitys growth and demographics.

Getting Started with the Template

To kick off using this template click on "Start with this Template" on Lazys platform. This will set up the template, on your Lazy Builder interface all set for customization and deployment.

Setting Up Initially

Before you start using the bot you have to create an environment, for the bot token. The bot token serves as an identifier that enables the Discord API to verify your bots identity.

1. Visit the Discord Developer Portal. Establish an application.

2. Click on the "Bot" section, Add Bot ". Confirm its creation.

3. Copy the provided bot token.

4. Return to the Lazy platform. Head over to the Environment Secrets tab.

5. Generate a secret labeled BOT_TOKEN and paste in the copied bot token as its value.

Once you've configured the environment secret your bot will be able to connect with Discord when its activated.

Testing; Trying Out The Test Feature

After configuring the environment secret click on the "Test" button within Lazy platform. This action will launch your bot without requiring any input from you.

Using The Application

Once your bot is up and running use the URL generated in Discord Developer Portal to invite it to your Discord server. Remember to provide permissions for reading messages and managing roles to ensure operation.

Upon invitation of your bot, to the server utilize these commands;

!member_count

This command shows you the count of members, bots and human members, in your server.

Use !member_count_role to see how many members are in each role on your server.

Setting up the App

You don't need to do any integration steps for this template. The bot will work on your Discord server once you invite it and grant the permissions.

If you face any problems or have questions about how the bot works check out the Discord API documentation for details, on bot development and permissions.

Enjoy using your Member Counter Discord Bot!

Technologies

Discord Automation & Bots Discord Automation & Bots

Similar templates

We found some blogs you might like...