spy bot

Python

Spy Bot - Monitoring bot for Discord

πŸ€– Spy Bot

Python Discord.py License: MIT Code style: black Imports: isort pre-commit Docker Make wakatime

A Discord bot for monitoring presence, status, and voice channels with beautiful notifications and detailed statistics for each user!


🌍 Languages


✨ Features

🎯 Basic Monitoring

  • Automatic notifications for joining, leaving, and changing voice channels (except excluded channel)
  • Status monitoring (online, idle, do not disturb, offline)
  • Platform detection (Mobile/Desktop) for joins and leaves
  • Beautiful messages using embeds and emojis
  • Data persistence in MongoDB

πŸ† Rankings and Achievements System

  • Automatic achievements based on online time, voice activity, and engagement
  • Competitive rankings of the most active members
  • Achievement notifications when unlocked
  • Medals and badges for different types of activity

πŸ“Š Advanced Commands

  • !stats
    β€” Detailed personal statistics
  • !top
    β€” Ranking of the 10 most active members
  • !top voice
    β€” Ranking of those who used voice the most
  • !achievements
    β€” Your achievements
  • !compare @user1 @user2
    β€” Compare users
  • !serverstats
    β€” General server statistics
  • !clear
    β€” Clear all messages from the current channel (requires permission)
  • !silence
    β€” Shows a tutorial on how to mute the channel manually in Discord (via DM)
  • !help
    β€” List of commands

⚠️ Alerts and Reminders

  • Inactivity alerts for absent members
  • Automatic notifications for inactive users
  • Flexible configuration of days for alerts

πŸ”‡ Silence System

  • User-controlled notifications - Users can silence bot notifications
  • Flexible duration - Temporary (hours/days) or permanent silence
  • Automatic expiration - Temporary silences expire automatically
  • Permission-based access - Requires "Manage Messages" permission

πŸ“ˆ Automatic Reports

  • Weekly reports with general statistics
  • Top users of the week
  • Server activity rate
  • Achievements granted in the period
  • Automatic scheduling (Sunday at 8 PM)

πŸ’€ Sleep Mode

  • !sleep
    β€” Puts the bot to sleep until it receives
    !wake
    .
  • !sleep 30m
    /
    !sleep 2h
    /
    !sleep 1d
    β€” Bot sleeps for the specified time (minutes, hours, days).
  • !wake
    β€” Wakes the bot up immediately.
  • !status-sleep
    β€” Shows the current sleep mode status.

While sleeping:

  • The bot continues collecting all metrics normally (presence, voice, messages, achievements, etc).
  • The bot does not send automatic messages (reports, alerts, unlocked achievements, etc).
  • The bot still responds to commands.

Silence Commands:

  • !silence
    β€” Shows a tutorial on how to mute the channel manually in Discord (via DM).

The !silence command only teaches you how to mute the channel manually. The bot cannot mute channels for you, as this is a personal Discord setting.

Ranking Commands:

  • !top
    β€” Ranking of the 10 members with the most online time
  • !top voice
    β€” Ranking of the 10 members with the most time in voice channels

Achievement Commands:

  • !achievements
    β€” Shows your unlocked achievements
  • !achievements @user
    β€” Shows achievements of another user
  • !achievements-categories
    β€” Shows all achievement categories and how many there are in each (dare to collect them all!)

Achievement Categories (Examples):

  • 🎀 Voice & Presence β€” For the most sociable! (e.g., stay 24h in voice?)
  • πŸ’¬ Messages & Reactions β€” For the most active! (1000 messages in a day?)
  • πŸ¦‹ Social & Community β€” For the most popular! (help 50 people?)
  • πŸ“ˆ Engagement & Usage β€” For the most dedicated! (7 days online without a break?)
  • ⏰ Activity & Consistency β€” For the most persistent! (30 days in a row?)
  • 🎲 Fun & Extras β€” For the most creative! (use all custom emojis?)
  • πŸŒ™ Discord Lunatic β€” For the craziest! (online at dawn?)

Unlock all 50 achievements and become a Discord legend! Less than 1% can do it... Will you?

Comparison Commands:

  • !compare @user1 @user2
    β€” Compares statistics of two users

Server Commands:

  • !serverstats
    β€” General server statistics

Silence System Examples:

Temporary Silence:

  • !silence_2h
    β€” Silence notifications for 2 hours
  • !silence_1d
    β€” Silence notifications for 1 day
  • !silence_7d
    β€” Silence notifications for 1 week

Permanent Silence:

  • !silence_always
    β€” Permanently silence all bot notifications

Management:

  • !silence_status
    β€” Check current silence status
  • !silence_remove
    β€” Remove silence and resume notifications

πŸš€ Installation

Option 1: Docker (Recommended)

The easiest way to run Spy Bot is using Docker Compose, which includes MongoDB:

  1. Clone the repository:

    git clone <repository-url>
    cd spy-bot
    
  2. Configure the

    .env
    file:

    • Copy the example:

      cp env.example .env
      
    • Fill in with your bot token, notification channel ID, and MongoDB credentials.

  3. Run with Docker Compose:

    docker-compose up -d
    

    This will start both the bot and MongoDB automatically.

Option 2: Manual Installation

  1. Clone the repository:

    git clone <repository-url>
    cd spy-bot
    
  2. Create the virtual environment:

    python3 -m venv venv
    source venv/bin/activate
    
  3. Install dependencies:

    pip install -r requirements.txt
    
  4. Configure the

    .env
    file:

    • Copy the example:

      cp env.example .env
      
    • Fill in with your bot token, notification channel ID, and MongoDB connection string.

    ⚠️ Important: If you're using

    export $(grep -v '^#' .env | xargs)
    to load variables, make sure values with spaces are in quotes in the
    .env
    file:

    # Correct (with quotes)
    REPORT_TIME="sunday 20:00"
    
    # Incorrect (without quotes)
    REPORT_TIME=sunday 20:00
    
  5. Run the bot:

    python main.py
    

βš™οΈ
.env
Configuration

For Docker Installation:

# Required Settings
DISCORD_BOT_TOKEN=your_token_here
CANAL_DE_NOTIFICACAO_ID=1234567890123456789

# MongoDB Settings (for Docker)
MONGO_INITDB_ROOT_USERNAME=admin
MONGO_INITDB_ROOT_PASSWORD=password123
MONGO_INITDB_DATABASE=spy
MONGODB_URI=mongodb://admin:password123@alert-mongo:27017/spy?authSource=admin

# Optional Settings
SALA_EXCLUIDA=VACA WORK OS BRABO
CANAL_RELATORIOS_ID=1234567890123456789
CANAL_ALERTAS_ID=1234567890123456789
REPORT_TIME=sunday 20:00
ALERT_INACTIVE_DAYS=7

For Manual Installation:

# Required Settings
DISCORD_BOT_TOKEN=your_token_here
CANAL_DE_NOTIFICACAO_ID=1234567890123456789
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/?retryWrites=true&w=majority

# Optional Settings
SALA_EXCLUIDA=VACA WORK OS BRABO
CANAL_RELATORIOS_ID=1234567890123456789
CANAL_ALERTAS_ID=1234567890123456789
REPORT_TIME=sunday 20:00
ALERT_INACTIVE_DAYS=7

Required Settings:

  • DISCORD_BOT_TOKEN: Your bot token from Discord Developer Portal
  • CANAL_DE_NOTIFICACAO_ID: ID of the channel where notifications will be sent
  • MONGODB_URI: MongoDB connection URI (for manual installation)

Docker-specific Settings:

  • MONGO_INITDB_ROOT_USERNAME: MongoDB root username (for Docker)
  • MONGO_INITDB_ROOT_PASSWORD: MongoDB root password (for Docker)
  • MONGO_INITDB_DATABASE: MongoDB database name (for Docker)

Optional Settings:

  • SALA_EXCLUIDA: Name of the voice channel that will be ignored by monitoring
  • CANAL_RELATORIOS_ID: ID of the channel where weekly reports will be sent
  • CANAL_ALERTAS_ID: ID of the channel where inactivity alerts will be sent
  • REPORT_TIME: Time for sending the weekly report (default: "sunday 20:00")
  • ALERT_INACTIVE_DAYS: Number of days to consider a user inactive (default: 7)

πŸ•ΉοΈ Commands

Basic Commands:

  • !stats
    β€” Shows your statistics of time in status and voice channels
  • !clear
    β€” Clear all messages from the current channel (requires "Manage Messages" permission)
  • !help
    β€” List of all available commands

Silence Commands:

  • !silence
    β€” Shows a tutorial on how to mute the channel manually in Discord (via DM).

The !silence command only teaches you how to mute the channel manually. The bot cannot mute channels for you, as this is a personal Discord setting.

Ranking Commands:

  • !top
    β€” Ranking of the 10 members with the most online time
  • !top voice
    β€” Ranking of the 10 members with the most time in voice channels

Achievement Commands:

  • !achievements
    β€” Shows your unlocked achievements
  • !achievements @user
    β€” Shows achievements of another user
  • !achievements-categories
    β€” Shows all achievement categories and how many there are in each (dare to collect them all!)

Achievement Categories (Examples):

  • 🎀 Voice & Presence β€” For the most sociable! (e.g., stay 24h in voice?)
  • πŸ’¬ Messages & Reactions β€” For the most active! (1000 messages in a day?)
  • πŸ¦‹ Social & Community β€” For the most popular! (help 50 people?)
  • πŸ“ˆ Engagement & Usage β€” For the most dedicated! (7 days online without a break?)
  • ⏰ Activity & Consistency β€” For the most persistent! (30 days in a row?)
  • 🎲 Fun & Extras β€” For the most creative! (use all custom emojis?)
  • πŸŒ™ Discord Lunatic β€” For the craziest! (online at dawn?)

Unlock all 50 achievements and become a Discord legend! Less than 1% can do it... Will you?

Comparison Commands:

  • !compare @user1 @user2
    β€” Compares statistics of two users

Server Commands:

  • !serverstats
    β€” General server statistics

Silence System Examples:

Temporary Silence:

  • !silence_2h
    β€” Silence notifications for 2 hours
  • !silence_1d
    β€” Silence notifications for 1 day
  • !silence_7d
    β€” Silence notifications for 1 week

Permanent Silence:

  • !silence_always
    β€” Permanently silence all bot notifications

Management:

  • !silence_status
    β€” Check current silence status
  • !silence_remove
    β€” Remove silence and resume notifications

πŸ“¦ Dependencies

Core Dependencies:

  • discord.py>=2.0.0
    - Discord API wrapper
  • python-dotenv>=0.19.0
    - Environment variable management
  • pymongo>=4.0.0
    - MongoDB driver

Development Dependencies:

  • black>=23.0.0
    - Code formatter
  • flake8>=6.0.0
    - Linter
  • isort>=5.12.0
    - Import sorter
  • bandit>=1.7.5
    - Security linter
  • pre-commit>=3.0.0
    - Git hooks

Installation:

# Production dependencies
pip install -r requirements.txt

# Development dependencies
pip install -e .[dev]

πŸ’‘ Usage Example

Automatic Notifications:

  • The bot sends automatic and beautiful messages when joining/leaving/changing voice channels:

    Embed example

Personal Statistics:

  • Use
    !stats
    to see your online time, idle time, time in each channel, etc.:

    Stats example

Achievement System:

  • ⏰ First Hour β€” Stayed online for 1 hour
  • πŸ”₯ Dedicated β€” Stayed online for 10 hours
  • πŸ‘‘ Veteran β€” Stayed online for 50 hours
  • 🎀 Voice Explorer β€” Spent 1 hour in voice channels
  • 🎡 Voice Master β€” Spent 10 hours in voice channels
  • πŸ¦‹ Social Butterfly β€” Visited 3 different channels
  • 🏠 Channel Explorer β€” Visited 10 different channels

Weekly Reports:

  • Automatically sent every Sunday at 8 PM
  • Include top users, general statistics, and weekly achievements

πŸ›‘οΈ Security

  • Never share your
    .env
    !
  • The
    .env
    file and sensitive data are in
    .gitignore
    .

πŸ”§ Troubleshooting

Environment variables problem:

If you get the error

export: not an identifier
when loading
.env
, it's because some variable contains spaces. Solutions:

  1. Use quotes in the

    .env
    file:

    REPORT_TIME="sunday 20:00"
    
  2. Or use python-dotenv (recommended):

    from dotenv import load_dotenv
    load_dotenv()
    
  3. Or load manually:

    source .env
    

Bot doesn't respond to commands:

  • Check if the bot has permission to read messages
  • Confirm that
    MESSAGE_CONTENT_INTENT
    is enabled in the Discord Developer Portal

Reports are not sent:

  • Check if
    CANAL_RELATORIOS_ID
    is configured correctly
  • Confirm that the bot has permission to send messages in the channel

Docker issues:

  • MongoDB connection failure: Check if the MongoDB container is running with
    docker-compose ps
  • Bot doesn't start: Check logs with
    docker-compose logs alert-bot
  • Environment variables not loaded: Make sure the
    .env
    file exists and has correct format
  • Port conflicts: Change MongoDB port in
    docker-compose.yml
    if 27843 is already in use

πŸ“„ License