Author: CyberPanther232
CleanSweep is a Discord moderation and housekeeping bot built to automate long-term message cleanup while preserving operational visibility. It can monitor selected channels, remove messages based on retention policy and message filters, back up deleted content, compress archived data, and restore important messages from backup storage when needed. This bot is intended for homelab enthusiasts and regular discord server admins that are looking for new ways to clean up their server chats.
Features
- Monitor one or more Discord channels for scheduled cleanup.
- Persist monitored services in
service.csvso the bot can resume after restart. - Delete messages based on retention age and configuration-driven filters.
- Back up deleted messages before removal.
- Search active and compressed backups.
- Restore deleted messages from backup storage.
- Compress backup and log archives once configured size thresholds are reached.
- Remove CleanSweep-authored messages with an admin-only cleanup command.
!service #channelstarts monitoring the selected channel.!stopstops monitoring the current channel.!pause-servicespauses the deletion sweep.!resume-servicesresumes the deletion sweep.!list-servicesshows currently monitored channels.!list-configshows the loaded configuration values.!reload-configreloadscs.confwithout restarting the bot.!set-config KEY VALUEupdates a loaded configuration value in memory.!save-configwrites the current in-memory configuration back tocs.conf.!search-backups <query>searches backups and compressed archives.!restore <message_id>restores a deleted message from backup storage.!remove-bot-messagesremoves CleanSweep-authored messages from the current channel.!cleansweep-helpshows the bot help text.
Configuration is stored in cs.conf.
Important settings include:
MESSAGE_RETENTION_DAYS: age threshold before a message is eligible for deletion.MESSAGE_CHECK_INTERVAL: seconds between sweep cycles.LOGGING_ENABLED: enables runtime log file persistence.LOG_FILE_PATH: file path or folder path for logs.LOG_COMPRESS_THRESHOLD_MB: compresses logs into.gzarchives when the active log exceeds the configured size.MESSAGE_BACKUP_ENABLED: enables backup before deletion.BACKUP_FILE_PATH: file path or folder path for backups.BACKUP_COMPRESS_THRESHOLD_MB: compresses backups into.gzarchives when the active backup exceeds the configured size.DELETE_RATE_LIMIT_SECONDS: delay between deletion operations.
Folder-style paths are supported. For example:
LOG_FILE_PATH = "logs/"BACKUP_FILE_PATH = "backups/"LOG_FILE_PATH = "/app/logs/"BACKUP_FILE_PATH = "/app/backups/"
- Python 3.13 or compatible runtime
- A Discord bot token with the required gateway intents and channel permissions
pip install -r requirements.txtCreate a .env file with your bot token:
DISCORD_TOKEN=your_token_herepython main.pyThis project already includes a Dockerfile.
docker build -t cleansweep .docker run --env-file .env --name cleansweep-bot cleansweepIf you want logs, backups, or service state to persist outside the container, mount local folders into /app:
docker run \
--env-file .env \
-v ./logs:/app/logs \
-v ./backups:/app/backups \
-v ./service.csv:/app/service.csv \
--name cleansweep-bot \
cleansweepCleanSweep/
├── Dockerfile
├── ReadMe.md
├── cs.conf
├── main.py
├── requirements.txt
├── service.csv
├── logs/
└── backups/
- The bot relies on Discord permissions to read history, delete messages, and post responses.
- Message restoration reposts a preserved copy of the deleted content, not the original Discord message object.
- Compressed backups and logs are stored as
.gzarchives in the same directory as their active files.