A comprehensive Discord bot that automatically collects and provides detailed server statistics through a web API. Available in both Python (discord.py) and Node.js (discord.js) versions.
- General Details: Server name, ID, icon, owner information, creation date
- Boost Status: Server boost level and boost count
- Description: Server description if available
- Total Count: All members including bots
- Human vs Bot Count: Separate counting of real users and bots
- Online Status: Count of currently online members
- Voice Activity: Members currently in voice channels
- Newest Member: Information about the most recently joined member
- Channel Counts: Text channels, voice channels, and categories
- Detailed List: Complete channel information including names, IDs, types, and categories
- Role Count: Total number of roles (excluding @everyone)
- Role Details: Name, ID, color, and member count for each role
- Custom Emojis: Count and details of all custom server emojis
- Emoji Information: Names, IDs, URLs, and animation status
- Streaming: Members currently streaming on platforms like Twitch
- Gaming: Members currently playing games
- Activity Details: Game names and streaming URLs
- Python 3.8+
- discord.py
- requests
- Node.js 16+
- discord.js v14
- express
- axios
- dotenv
git clone https://github.com/yourusername/discord-stats-bot.git
cd discord-stats-botpip install discord.py requestsnpm install
# or use the provided setup script
chmod +x setup.sh
./setup.shCopy the .env.example to .env and fill in your credentials:
cp .env.example .env# Discord Bot Token (from Discord Developer Portal)
DISCORD_TOKEN="YOUR_DISCORD_BOT_TOKEN_HERE"
# Discord Server ID (Guild ID)
SERVER_ID="123456789012345678"
# API Key for internal communication
API_KEY="your-secure-random-api-key-here-32-characters-minimum"- Go to Discord Developer Portal
- Create a new application
- Navigate to the "Bot" section
- Create a bot and copy the token
- Enable the following Privileged Gateway Intents:
- Server Members Intent
- Presence Intent
- Invite the bot to your server with appropriate permissions
- Enable Developer Mode in Discord:
- User Settings β Advanced β Developer Mode
- Right-click on your server name
- Click "Copy Server ID"
python bot.pynode app.js
# or
./setup.shUpdates the server statistics (used internally by the bot)
Headers:
X-API-Key: Your API keyContent-Type: application/json
Retrieves current server statistics
Response Example:
{
"last_updated": "2025-07-30T12:00:00.000Z",
"server": {
"name": "My Discord Server",
"id": "123456789012345678",
"icon_url": "https://cdn.discordapp.com/icons/...",
"owner_name": "ServerOwner",
"boost_level": 2,
"boost_count": 5
},
"members": {
"total_count": 150,
"human_count": 130,
"bot_count": 20,
"online_count": 45
},
"channels": {
"text_channel_count": 15,
"voice_channel_count": 8,
"category_count": 5
}
}Simple health check endpoint
discord-stats-bot/
βββ bot.py # Python version of the bot
βββ app.js # Node.js version with web server
βββ setup.sh # Setup script for Node.js version
βββ .env.example # Environment variables template
βββ .gitignore # Git ignore file
βββ package.json # Node.js dependencies
βββ requirements.txt # Python dependencies
βββ README.md # This file
- Python Version: 1 minute (configurable in
@tasks.loop()) - Node.js Version: 2 minutes (configurable in
setInterval())
Both versions can send data to external APIs. Configure the API_ENDPOINT in your environment or code:
Python Version:
API_ENDPOINT = os.getenv("API_ENDPOINT", "https://your-website.com/api/update_stats")Node.js Version: The Node.js version includes a built-in web server and API, but can also be configured to send data externally.
- Never commit your
.envfile - Add it to.gitignore - Keep your bot token secret - Regenerate if compromised
- Use strong API keys - Generate random strings of 32+ characters
- Limit bot permissions - Only grant necessary Discord permissions
- Validate API requests - The bot includes API key validation
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
If you encounter any issues:
- Check that all environment variables are properly set
- Ensure the bot has the required permissions on your Discord server
- Verify that Privileged Gateway Intents are enabled
- Check the console for error messages
| Feature | Python Version | Node.js Version |
|---|---|---|
| Web Server | β External API only | β Built-in Express server |
| API Endpoints | β | β GET/POST endpoints |
| Update Interval | 1 minute | 2 minutes |
| Dependencies | discord.py, requests | discord.js, express, axios |
| Use Case | Simple stats collection | Full web application |
Choose the Python version for simple statistics collection, or the Node.js version if you need a complete web application with API endpoints.