simple discord bot that deletes old messages in text channels on a rolling basis using purge
- requires the absolute minimum permissions. no message content access
- purge durations are kept in a local SQLite database and resumed on bot restart
- pinned messages are left untouched
rest in peace @AutoDelete#6949 which inspired this project
@kms_bot_user 10d
@kms_bot_user 12h
@kms_bot_user 5m
@kms_bot_user 30s
or any custom duration
@kms_bot_user stop
@kms_bot_user status
@kms_bot_user help
python 3.8 or higher is required
git clone https://github.com/internetisgone/kms-bot.git
cd kms-bot
go to discord developer portal and create a new application
in the "bot" section, copy its token and paste it in .env.example, and rename the file to .env. optionally, uncheck "public bot"
in the "OAuth2 - URL generator" section, set scope to bot, and select the send messages, manage messages, and read message history permissions. invite the bot to your server with the link
create and activate a venv
# macos and linux
python3 -m venv .venv
source .venv/bin/activate
# windows
py -m venv .venv
.venv\Scripts\activate.bat
install requirements
pip install -r requirements.txt
run the bot
# macos and linux
python3 main.py
# windows
py main.py
- fly.io. it will build the bot from the
Dockerfile. u need to configure a volume for the sqlite db to work - pythonanywhere. afaik it has persistent storage but the machine gets restarted quite often
(optional) add the bot as a systemd service so it starts automatically on system startup
create a kms.service config file at /etc/systemd/system/
nano /etc/systemd/system/kms.service
the config should look something like this
[Unit]
Description=kms discord bot
After=network-online.target
[Service]
Type=simple
User=[your username here]
Restart=on-failure
WorkingDirectory=/path/to/bot
Environment="PYTHONPATH=$PYTHONPATH:/usr/lib/python[version]/site-packages"
ExecStart=/path/to/bot/.venv/bin/python3 /path/to/bot/main.py
[Install]
WantedBy=multi-user.target
enable and start the service
systemctl enable kms
systemctl start kms
check service status
systemctl status kms
view most recent log
journalctl -u kms -n 50