Discord Server Stats Bot

import os
import discord
from discord.ext import commands
from datetime import datetime, timedelta
from collections import Counter
import pytz

intents = discord.Intents.all()
bot = commands.Bot(command_prefix='!', intents=intents)

async def serverstats(ctx):
    # Total number of members in the server.
    total_members = ctx.guild.member_count
    progress_message = await ctx.reply('Gathering stats...')
    await progress_message.edit(content='Gathered total members...')

    # Number of online members.
    online_members = len([member for member in ctx.guild.members if member.status == discord.Status.online])
    await progress_message.edit(content='Gathered online members...')

    # Number of offline members.
    offline_members = len([member for member in ctx.guild.members if member.status == discord.Status.offline])

About this template

The Discord server stats bot requires certain permissions to function properly. These include the ability to read message history, send messages, and react to messages. The bot will generate stats such as total members, online members, offline members, bots, text channels, voice channels, roles, server creation date, and members joined in the last 24 hours. Please provide the Discord bot token in the Env Secrets tab under the name 'DISCORD_BOT_TOKEN'.

Introduction to the Discord Server Stats Bot Template

Welcome to the step-by-step guide on how to set up and use the Discord Server Stats Bot. This bot is designed to provide you with comprehensive statistics about your Discord server, including member counts, channel information, and activity metrics. Whether you're a server administrator looking to monitor growth or a curious member interested in server dynamics, this bot will serve your needs without the hassle of manual data collection.

To begin using this template, simply click on "Start with this Template" on the Lazy platform. This will set up the template in your Lazy Builder interface, and you can proceed with the following steps to get your bot up and running.

Setting Environment Secrets

Before you can use the bot, you need to provide a Discord bot token. This token allows your bot to interact with the Discord API and is essential for the bot's functionality. Here's how to set it up:

  • Go to the Discord Developer Portal and create a new application.
  • Within your application, navigate to the "Bot" tab and create a new bot.
  • Copy the bot token provided.
  • Back in the Lazy Builder interface, locate the Environment Secrets tab.
  • Create a new secret with the name 'DISCORD_BOT_TOKEN' and paste your copied bot token as the value.

With the environment secret set, your bot is now ready to be deployed.

External Integrations

For the bot to function correctly, you need to invite it to your Discord server and ensure it has the necessary permissions. Follow these steps:

  • In the Discord Developer Portal, under your bot's application, navigate to the "OAuth2" tab.
  • Under "SCOPES," select "bot" and then choose the permissions your bot will need, such as reading message history, sending messages, and reacting to messages.
  • Use the generated URL to invite your bot to the desired Discord server.

Ensure that your bot has been added to the server and has the appropriate roles and permissions to access the channels and information it needs to generate statistics.

Using the Test Button

Once you have set up the environment secret and invited the bot to your server, you can deploy the bot using the Test button on the Lazy platform. This will launch the Lazy CLI, and the bot will start running. No further user input is required at this stage unless you want to interact with the bot commands within your Discord server.

To use the bot, simply type the command '!serverstats' in any text channel where the bot has permission to read and send messages. The bot will begin compiling server statistics and will provide you with a detailed report. If you want to get channel-specific statistics, use the command '!channelstats ' by replacing with the actual name of the channel you're interested in.

Interacting with the Bot

After deploying the bot, you can interact with it directly on your Discord server. Here are some commands you can use:

To get general server statistics:


To get statistics for a specific channel:

!channelstats channel-name

Replace 'channel-name' with the name of the channel you want to analyze. The bot will respond with the requested statistics.

By following these steps, you should have a fully functional Discord Server Stats Bot running on your server. Enjoy the insights and convenience this bot brings to managing and understanding your Discord community!

Last published
June 15, 2024

More templates like this

Discord Ticketbot Template

A simple Discord Ticketbot for your Discord Support Department. This Template and Bot is fully customizable but already build so that you can use it right away. You need a bot token from https://discord.com/developers/applications for your bot to work. These are the steps needed to get your token: "1. 🌐 Go to the Discord Developer Portal. 🌐\n" + "2. 🆕 Create a new application and navigate to the 'Bot' section. 🤖\n" + "3. 📋 Under the 'TOKEN' section, click 'Reset Token' to get your Discord bot token and confirm by clicking 'Yes, do it'. 🔑\n" + "4. 🤖 If your bot will have any ability to read/reply to messages, then under the 'BOT' section, enable the slider titled 'Message Content Intent' ✅" + "5. 🔐 Set the 'DISCORD_BOT_TOKEN' in the Env Secrets tab with your bot token from step 3. 🔐\n" + "For bot permissions, it's recommended to start with basic permissions and adjust as needed for your app's functionality.🚀") If you encounter any bugs, please tell Lazy to fix them and report them on the Official Lazy AI Discord to @D4vidG4merLP. Credits: @meow - the Discord bot slash command template @mrlazy.notlazy - supporting me And the Biggest Thank you. You for using this template ❤️


Discord bot using slash commands in python

Just a cute /ping bot


Basic Discord Bot

A Discord bot that does nothing (excellent starting point). Think of it as the plain paper of Discord bots. It does nothing at all and you can turn it into whatever you want. All you need to set is a Discord bot token from your Discord developer portal and boom! You're done.

Discord Server Stats Bot