A bot that allows you to set a message retention for individual Discord text channels.
- Automatically delete messages that are older than a configured time
- Don't delete pinned messages until configured otherwise
- Multi channel configuration (e.g. keep messages
#general
for two weeks, but#random
for one day) - Default configuration for all channels without definend retention
Before running your bot you need to create it on Discord:
- Create a Discord Application in the Discord Developer Portal
- Go to
Bot
and clickAdd Bot
and make sure to uncheckPublic bot
- Copy the
CLIENT ID
from theGeneral Information
tab - Go to https://discord.com/oauth2/authorize?client_id=$CLIENT_ID&scope=bot&permissions=74752 and add your bot to your Discord server
74752 is the bitmask for the following permissions:
- View Channels
- Manage Messages
- Read Message History
You can verify this by checking these in the Bot Permissions mask on your bots page.
Go to the GitHub Releases and download the binary for your architecture.
You can use the provided Docker image at
docker.pkg.github.com/bahlo/discord-retention-bot/discord-retention-bot:1.0.2
.
Run cargo install discord-retention-bot
to install the latest version from
crates.io.
- Clone the repository with
git clone https://github.com/bahlo/discord-retention-bot
- Run
cargo build --release
to build your binary totarget/release/discord-retention-bot
Configure your bot via environment variables (optionally in an .env
file).
Tihs defines the log level. I recommend setting this to
discord-retention-bot=info
for normal usage.
The token of your Discord bot. Get it from the Discord Developer Portal by going to your application → Bot and copying the token.
Can be set to true
or false
. If set to true
, pinned messages
will also be deleted. Defaults to false
.
A list of channel names and the duration after which messages should be deleted,
separated by a comma. You can also configure *
to match all unconfigured
channnels.
The duration is a number followed by one of h
(hours), d
(days), and w
(weeks).
Please note that this configuration applies to all guilds your bot is added to.
general:2w,random:4d,*:4w
will result in messages being deleted in
general
: after two weeksrandom
: after four days- every other channel after four weeks
Discord might be rate-limiting you. This applications uses the single message delete endpoint because Bulk Delete Messages doesn't support messages older than 2 weeks. It might take a while the first time, but it will get faster.
Make sure the bot has access to that channel in the Discord application and the following permissions:
- Read Text Channels & See Voice Channels
- Manage Messages
- Read Message History
To run integration tests you need to create a bot (see Preparation), but with the bitmask 76816, which translates to:
- Manage Channels
- View Channels
- Send Messages
- Manage Messages
- Read Message History
Export the bot token to INTEGRATION_DISCORD_TOKEN
and run cargo test -- --ignored
to run the integration tests.