Discord
Use this skill when implementing or automating Discord integrations.
Pick the right approach
Incoming webhooks (best for one-way posting)
Bot token + REST API (two-way / richer automation)
- Use when you need to post as a bot, manage channels, read history, moderate, etc.
- REST API base:
https://discord.com/api/v10
- Most REST calls use
Authorization: Bot <token>.
Interactions / slash commands (user-invoked commands)
- Use application commands and interaction webhooks.
- Typically requires running a web server to receive interactions and respond quickly.
Secrets & safety
- Never hard-code tokens. Use environment variables:
DISCORD_WEBHOOK_URL for incoming webhooks
DISCORD_BOT_TOKEN for bot REST API calls
- Treat webhook URLs as secrets (they include a token).
- Do not automate normal user accounts (“self-bots”). Use official bot/OAuth flows.
Footguns / safety notes (read this)
- Webhook URLs are secrets (the token is embedded in the URL). Don’t paste them into issues, logs, CI output, or chat.
- Mentions are dangerous by default: always set
allowed_mentions to something strict (these examples use {"parse": []}) to avoid accidentally pinging @everyone / roles.
- Watch for accidental secret logging:
- If you build your own scripts, avoid including full webhook URLs in exception messages.
- The bundled scripts sanitize webhook URLs in error output, but you should still avoid printing the URL yourself.
- Rate limits: handle HTTP 429 with
retry_after/Retry-After, and don’t retry forever.
Quick recipes
The shell snippets below use POSIX-style environment variables and line continuations. On Windows PowerShell, use curl.exe for the shown flags and $env:DISCORD_WEBHOOK_URL / $env:DISCORD_BOT_TOKEN for environment variables, or translate the request to Invoke-RestMethod.
Post a message via an incoming webhook (recommended)
Discord requires at least one of content, embeds, components, file, or poll.
curl -sS -X POST \
-H 'Content-Type: application/json' \
-d '{"content":"Hello from OpenHands","allowed_mentions":{"parse":[]}}' \
"$DISCORD_WEBHOOK_URL"
Post a message to a channel with a bot token
Endpoint: POST /channels/{channel_id}/messages (Create Message)
CHANNEL_ID="..."
curl -sS -X POST "https://discord.com/api/v10/channels/${CHANNEL_ID}/messages" \
-H "Authorization: Bot $DISCORD_BOT_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"content":"Hello from my bot","allowed_mentions":{"parse":[]}}'
Docs: https://discord.com/developers/docs/resources/channel#create-message
Automation scripts (bundled)
These scripts are self-contained and only use the Python standard library.
Post to a webhook:
python3 -m skills.discord.scripts.post_webhook --content "Build finished" --wait
Post to a channel using a bot token:
python3 -m skills.discord.scripts.send_message --channel-id "$CHANNEL_ID" --content "Hello"
Rate limits
- Don’t hard-code limits. Use Discord’s
Retry-After / retry_after and rate-limit headers when present.
- On HTTP 429, wait for the provided delay (clamp to a sane maximum, add small jitter), then retry.
Docs: https://discord.com/developers/docs/topics/rate-limits
Slash commands / application commands
- Use guild commands for fast iteration (instant updates).
- Use global commands when ready; propagation can take longer.
Docs: https://discord.com/developers/docs/interactions/application-commands
Reference
For more details (OAuth2 flows, command registration endpoints, troubleshooting), see:
1---
2name: discord
3description: Build and automate Discord integrations (bots, webhooks, slash commands, and REST API workflows). Use when the user mentions Discord, a Discord server/guild, channels, webhooks, bot tokens, slash commands/application commands, discord.js, or discord.py.
4triggers:
5 - discord
6 - discord api
7 - discord bot
8 - discord webhook
9 - discord.js
10 - discord.py
11---
12
13# Discord
14
15Use this skill when implementing or automating Discord integrations.
16
17## Pick the right approach
18
191. **Incoming webhooks (best for one-way posting)**
20 - Good for CI notifications, alerts, build status, etc.
21 - No bot user needed.
22 - See: https://discord.com/developers/docs/resources/webhook#execute-webhook
23
242. **Bot token + REST API (two-way / richer automation)**
25 - Use when you need to post as a bot, manage channels, read history, moderate, etc.
26 - REST API base: `https://discord.com/api/v10`
27 - Most REST calls use `Authorization: Bot <token>`.
28
293. **Interactions / slash commands (user-invoked commands)**
30 - Use application commands and interaction webhooks.
31 - Typically requires running a web server to receive interactions and respond quickly.
32
33## Secrets & safety
34
35- **Never hard-code tokens**. Use environment variables:
36 - `DISCORD_WEBHOOK_URL` for incoming webhooks
37 - `DISCORD_BOT_TOKEN` for bot REST API calls
38- Treat webhook URLs as secrets (they include a token).
39- Do **not** automate normal user accounts (“self-bots”). Use official bot/OAuth flows.
40
41## Footguns / safety notes (read this)
42
43- **Webhook URLs are secrets** (the token is embedded in the URL). Don’t paste them into issues, logs, CI output, or chat.
44- **Mentions are dangerous by default**: always set `allowed_mentions` to something strict (these examples use `{"parse": []}`) to avoid accidentally pinging `@everyone` / roles.
45- **Watch for accidental secret logging**:
46 - If you build your own scripts, avoid including full webhook URLs in exception messages.
47 - The bundled scripts sanitize webhook URLs in error output, but you should still avoid printing the URL yourself.
48- **Rate limits**: handle HTTP 429 with `retry_after`/`Retry-After`, and don’t retry forever.
49
50## Quick recipes
51
52The shell snippets below use POSIX-style environment variables and line continuations. On Windows PowerShell, use `curl.exe` for the shown flags and `$env:DISCORD_WEBHOOK_URL` / `$env:DISCORD_BOT_TOKEN` for environment variables, or translate the request to `Invoke-RestMethod`.
53
54### Post a message via an incoming webhook (recommended)
55
56Discord requires at least one of `content`, `embeds`, `components`, `file`, or `poll`.
57
58```bash
59curl -sS -X POST \
60 -H 'Content-Type: application/json' \
61 -d '{"content":"Hello from OpenHands","allowed_mentions":{"parse":[]}}' \
62 "$DISCORD_WEBHOOK_URL"
63```
64
65### Post a message to a channel with a bot token
66
67Endpoint: `POST /channels/{channel_id}/messages` (Create Message)
68
69```bash
70CHANNEL_ID="..."
71
72curl -sS -X POST "https://discord.com/api/v10/channels/${CHANNEL_ID}/messages" \
73 -H "Authorization: Bot $DISCORD_BOT_TOKEN" \
74 -H 'Content-Type: application/json' \
75 -d '{"content":"Hello from my bot","allowed_mentions":{"parse":[]}}'
76```
77
78Docs: https://discord.com/developers/docs/resources/channel#create-message
79
80## Automation scripts (bundled)
81
82These scripts are self-contained and only use the Python standard library.
83
84- Post to a webhook:
85 ```bash
86 python3 -m skills.discord.scripts.post_webhook --content "Build finished" --wait
87 ```
88
89- Post to a channel using a bot token:
90 ```bash
91 python3 -m skills.discord.scripts.send_message --channel-id "$CHANNEL_ID" --content "Hello"
92 ```
93
94## Rate limits
95
96- Don’t hard-code limits. Use Discord’s `Retry-After` / `retry_after` and rate-limit headers when present.
97- On HTTP **429**, wait for the provided delay (clamp to a sane maximum, add small jitter), then retry.
98
99Docs: https://discord.com/developers/docs/topics/rate-limits
100
101## Slash commands / application commands
102
103- Use **guild commands** for fast iteration (instant updates).
104- Use **global commands** when ready; propagation can take longer.
105
106Docs: https://discord.com/developers/docs/interactions/application-commands
107
108## Reference
109
110For more details (OAuth2 flows, command registration endpoints, troubleshooting), see:
111- [references/REFERENCE.md](references/REFERENCE.md)