aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
blob: 7a8d638966370209fcc8339ee23945e8938e3a28 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Timeoutinator

A Discord bot that instantly **timeouts** anyone who posts in a configured channel and **purges** all of their messages from the last 24 hours.

## How it works

1. User sends a message in the policed channel.
2. Bot immediately times them out (`Moderate Members` — configurable duration, default 1 hour).
3. Bot bulk-deletes every message that user posted **in any channel of the guild** over the past 24 hours (including the triggering message).

Bots, system messages, and webhook messages are ignored. The bot's own messages are also ignored. Concurrent handling of the same user is deduplicated so rapid-fire spam doesn't cause duplicate timeouts or purge races.

## Setup

### 1. Create a Discord Application

1. Go to [discord.com/developers/applications](https://discord.com/developers/applications)
2. Click **New Application** → name it → **Bot** tab → **Add Bot**
3. Under the bot, click **Reset Token** and copy the token — this is your `DISCORD_TOKEN`

### 2. Enable Required Intents

In the **Bot** tab, scroll to **Privileged Gateway Intents**.  
The bot only needs **Message Content** if you want to read message content — by default, only `GUILD_MESSAGES` is required, which is non-privileged. No privileged intents are required.

### 3. Invite the Bot

Use this URL (replace `YOUR_BOT_CLIENT_ID` with the bot's Client ID from the **General Information** tab):

```
https://discord.com/api/oauth2/authorize?client_id=YOUR_BOT_CLIENT_ID&permissions=1099511702528&scope=bot
```

Required permissions (encoded in the URL):

| Permission              | Why                                      |
|-------------------------|------------------------------------------|
| View Channels           | See the policed channel and the channels to purge                  |
| Read Message History    | Fetch messages to purge                  |
| Manage Messages         | Delete messages via bulk-delete endpoint |
| Moderate Members        | Apply timeouts                           |

### 4. Run

```bash
cp .env.example .env   # or export the env vars directly
# edit .env with your token and target channel ID

cargo run --release
```

## Environment Variables

| Variable              | Required | Default | Description                                                    |
|-----------------------|----------|---------|----------------------------------------------------------------|
| `DISCORD_TOKEN`       | ✅       | —       | Bot token from the Discord Developer Portal                    |
| `TARGET_CHANNEL_ID`   | ✅       | —       | Snowflake ID of the channel to police (right-click → Copy ID) |
| `TIMEOUT_MINUTES`     | ❌       | `60`    | Timeout duration in minutes (1–40320, i.e. up to 28 days)     |
| `PURGE_HOURS`         | ❌       | `24`    | How far back (hours) to look when deleting messages           |

## Requirements

- Rust 1.85+ (edition 2024)
- Network access (to fetch crates and connect to Discord's gateway)