discord-webhook
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDiscord Webhook
Discord Webhook
Use Discord Webhooks via direct calls to send messages to Discord channels without setting up a bot.
curlOfficial docs:https://discord.com/developers/docs/resources/webhook
通过直接调用来使用Discord Webhook,无需设置机器人即可向Discord频道发送消息。
curl官方文档:https://discord.com/developers/docs/resources/webhook
When to Use
适用场景
Use this skill when you need to:
- Send notifications to Discord channels
- Post alerts from CI/CD pipelines
- Share updates with rich embeds
- Upload files to channels
- Simple integrations without bot complexity
当你需要以下操作时,可以使用此方法:
- 发送通知到Discord频道
- 从CI/CD流水线推送告警
- 通过富嵌入内容分享更新
- 向频道上传文件
- 无需机器人复杂度的简单集成
Prerequisites
前提条件
- In Discord, go to Server Settings → Integrations → Webhooks
- Click "New Webhook"
- Choose a name and target channel
- Click "Copy Webhook URL"
bash
export DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/1234567890/abcdefg..."Security: Never expose webhook URLs publicly - they require no authentication.
Important: When usingin a command that pipes to another command, wrap the command containing$VARin$VAR. Due to a Claude Code bug, environment variables are silently cleared when pipes are used directly.bash -c '...'bashbash -c 'curl -s "https://api.example.com" -H "Authorization: Bearer $API_KEY"'
- 在Discord中,进入服务器设置 → 集成 → Webhooks
- 点击「新建Webhook」
- 选择名称和目标频道
- 点击「复制Webhook URL」
bash
export DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/1234567890/abcdefg..."安全提示: 切勿公开暴露Webhook URL——它们无需认证即可使用。
重要提示: 当在包含管道的命令中使用时,请将包含$VAR的命令用$VAR包裹。由于Claude Code的一个bug,直接使用管道时环境变量会被静默清除。bash -c '...'bashbash -c 'curl -s "https://api.example.com" -H "Authorization: Bearer $API_KEY"'
How to Use
使用方法
All examples below assume you have set.
DISCORD_WEBHOOK_URL以下所有示例均假设你已设置好环境变量。
DISCORD_WEBHOOK_URL1. Send Simple Message
1. 发送简单消息
Write to :
/tmp/discord_webhook_request.jsonjson
{
"content": "Hello from webhook!"
}Then run:
bash
curl -s -X POST "${DISCORD_WEBHOOK_URL}" -H "Content-Type: application/json" -d @/tmp/discord_webhook_request.json写入:
/tmp/discord_webhook_request.jsonjson
{
"content": "Hello from webhook!"
}然后运行:
bash
curl -s -X POST "${DISCORD_WEBHOOK_URL}" -H "Content-Type: application/json" -d @/tmp/discord_webhook_request.json2. Send with Custom Username and Avatar
2. 发送带自定义用户名和头像的消息
Write to :
/tmp/discord_webhook_request.jsonjson
{
"content": "Alert!",
"username": "Alert Bot",
"avatar_url": "https://i.imgur.com/4M34hi2.png"
}Then run:
bash
curl -s -X POST "${DISCORD_WEBHOOK_URL}" -H "Content-Type: application/json" -d @/tmp/discord_webhook_request.json写入:
/tmp/discord_webhook_request.jsonjson
{
"content": "Alert!",
"username": "Alert Bot",
"avatar_url": "https://i.imgur.com/4M34hi2.png"
}然后运行:
bash
curl -s -X POST "${DISCORD_WEBHOOK_URL}" -H "Content-Type: application/json" -d @/tmp/discord_webhook_request.json3. Send Rich Embed
3. 发送富嵌入内容
Write to :
/tmp/discord_webhook_request.jsonjson
{
"embeds": [
{
"title": "Deployment Complete",
"description": "Version 1.2.3 deployed to production",
"color": 5763719,
"fields": [
{
"name": "Environment",
"value": "Production",
"inline": true
},
{
"name": "Status",
"value": "Success",
"inline": true
}
],
"timestamp": "2025-01-01T12:00:00.000Z"
}
]
}Then run:
bash
curl -s -X POST "${DISCORD_WEBHOOK_URL}" -H "Content-Type: application/json" -d @/tmp/discord_webhook_request.jsonCommon colors (decimal):
- Green:
5763719 - Red:
15548997 - Blue:
5793266 - Yellow:
16776960 - Orange:
16744192
写入:
/tmp/discord_webhook_request.jsonjson
{
"embeds": [
{
"title": "Deployment Complete",
"description": "Version 1.2.3 deployed to production",
"color": 5763719,
"fields": [
{
"name": "Environment",
"value": "Production",
"inline": true
},
{
"name": "Status",
"value": "Success",
"inline": true
}
],
"timestamp": "2025-01-01T12:00:00.000Z"
}
]
}然后运行:
bash
curl -s -X POST "${DISCORD_WEBHOOK_URL}" -H "Content-Type: application/json" -d @/tmp/discord_webhook_request.json常用颜色(十进制):
- 绿色:
5763719 - 红色:
15548997 - 蓝色:
5793266 - 黄色:
16776960 - 橙色:
16744192
4. Send Error Alert
4. 发送错误告警
Write to :
/tmp/discord_webhook_request.jsonjson
{
"embeds": [
{
"title": "Error Alert",
"description": "Database connection failed",
"color": 15548997,
"fields": [
{
"name": "Service",
"value": "api-server"
},
{
"name": "Error",
"value": "Connection timeout"
}
],
"footer": {
"text": "Monitor"
}
}
]
}Then run:
bash
curl -s -X POST "${DISCORD_WEBHOOK_URL}" -H "Content-Type: application/json" -d @/tmp/discord_webhook_request.json写入:
/tmp/discord_webhook_request.jsonjson
{
"embeds": [
{
"title": "Error Alert",
"description": "Database connection failed",
"color": 15548997,
"fields": [
{
"name": "Service",
"value": "api-server"
},
{
"name": "Error",
"value": "Connection timeout"
}
],
"footer": {
"text": "Monitor"
}
}
]
}然后运行:
bash
curl -s -X POST "${DISCORD_WEBHOOK_URL}" -H "Content-Type: application/json" -d @/tmp/discord_webhook_request.json5. Send File Attachment
5. 发送附件文件
Write to :
/tmp/discord_webhook_payload.jsonjson
{
"content": "Screenshot attached"
}Then run:
bash
curl -s -X POST "${DISCORD_WEBHOOK_URL}" -F "file1=@screenshot.png" -F 'payload_json=@/tmp/discord_webhook_payload.json'写入:
/tmp/discord_webhook_payload.jsonjson
{
"content": "Screenshot attached"
}然后运行:
bash
curl -s -X POST "${DISCORD_WEBHOOK_URL}" -F "file1=@screenshot.png" -F 'payload_json=@/tmp/discord_webhook_payload.json'6. Send Multiple Files
6. 发送多个文件
Write to :
/tmp/discord_webhook_payload.jsonjson
{
"content": "Log files attached"
}Then run:
bash
curl -s -X POST "${DISCORD_WEBHOOK_URL}" -F "file1=@error.log" -F "file2=@debug.log" -F 'payload_json=@/tmp/discord_webhook_payload.json'写入:
/tmp/discord_webhook_payload.jsonjson
{
"content": "Log files attached"
}然后运行:
bash
curl -s -X POST "${DISCORD_WEBHOOK_URL}" -F "file1=@error.log" -F "file2=@debug.log" -F 'payload_json=@/tmp/discord_webhook_payload.json'7. Send Multiple Embeds
7. 发送多个嵌入内容
Write to :
/tmp/discord_webhook_request.jsonjson
{
"embeds": [
{
"title": "Build Started",
"color": 16776960
},
{
"title": "Tests Passed",
"color": 5763719
},
{
"title": "Deployed",
"color": 5793266
}
]
}Then run:
bash
curl -s -X POST "${DISCORD_WEBHOOK_URL}" -H "Content-Type: application/json" -d @/tmp/discord_webhook_request.json写入:
/tmp/discord_webhook_request.jsonjson
{
"embeds": [
{
"title": "Build Started",
"color": 16776960
},
{
"title": "Tests Passed",
"color": 5763719
},
{
"title": "Deployed",
"color": 5793266
}
]
}然后运行:
bash
curl -s -X POST "${DISCORD_WEBHOOK_URL}" -H "Content-Type: application/json" -d @/tmp/discord_webhook_request.json8. Send with Mention
8. 发送带提及的消息
Write to :
/tmp/discord_webhook_request.jsonjson
{
"content": "<@<your-user-id>> Check this out!",
"allowed_mentions": {
"users": ["<your-user-id>"]
}
}Then run:
bash
curl -s -X POST "${DISCORD_WEBHOOK_URL}" -H "Content-Type: application/json" -d @/tmp/discord_webhook_request.jsonReplace with the actual Discord user ID.
<your-user-id>写入:
/tmp/discord_webhook_request.jsonjson
{
"content": "<@<your-user-id>> Check this out!",
"allowed_mentions": {
"users": ["<your-user-id>"]
}
}然后运行:
bash
curl -s -X POST "${DISCORD_WEBHOOK_URL}" -H "Content-Type: application/json" -d @/tmp/discord_webhook_request.json将替换为实际的Discord用户ID。
<your-user-id>9. Send Silent Message (No Notification)
9. 发送静默消息(无通知)
Write to :
/tmp/discord_webhook_request.jsonjson
{
"content": "Silent update",
"flags": 4096
}Then run:
bash
curl -s -X POST "${DISCORD_WEBHOOK_URL}" -H "Content-Type: application/json" -d @/tmp/discord_webhook_request.json写入:
/tmp/discord_webhook_request.jsonjson
{
"content": "Silent update",
"flags": 4096
}然后运行:
bash
curl -s -X POST "${DISCORD_WEBHOOK_URL}" -H "Content-Type: application/json" -d @/tmp/discord_webhook_request.json10. CI/CD Pipeline Notification
10. CI/CD流水线通知
Write to :
/tmp/discord_webhook_request.jsonjson
{
"username": "GitHub Actions",
"embeds": [
{
"title": "Pipeline Status",
"color": 5763719,
"fields": [
{
"name": "Repository",
"value": "myorg/myrepo",
"inline": true
},
{
"name": "Branch",
"value": "main",
"inline": true
},
{
"name": "Commit",
"value": "abc1234",
"inline": true
},
{
"name": "Status",
"value": "Success"
}
],
"timestamp": "2025-01-01T12:00:00.000Z"
}
]
}Then run:
bash
curl -s -X POST "${DISCORD_WEBHOOK_URL}" -H "Content-Type: application/json" -d @/tmp/discord_webhook_request.json写入:
/tmp/discord_webhook_request.jsonjson
{
"username": "GitHub Actions",
"embeds": [
{
"title": "Pipeline Status",
"color": 5763719,
"fields": [
{
"name": "Repository",
"value": "myorg/myrepo",
"inline": true
},
{
"name": "Branch",
"value": "main",
"inline": true
},
{
"name": "Commit",
"value": "abc1234",
"inline": true
},
{
"name": "Status",
"value": "Success"
}
],
"timestamp": "2025-01-01T12:00:00.000Z"
}
]
}然后运行:
bash
curl -s -X POST "${DISCORD_WEBHOOK_URL}" -H "Content-Type: application/json" -d @/tmp/discord_webhook_request.jsonEmbed Structure
嵌入内容结构
json
{
"title": "Title text",
"description": "Description text",
"url": "https://example.com",
"color": 5763719,
"fields": [
{"name": "Field 1", "value": "Value 1", "inline": true}
],
"author": {"name": "Author", "icon_url": "https://..."},
"footer": {"text": "Footer text"},
"thumbnail": {"url": "https://..."},
"image": {"url": "https://..."},
"timestamp": "2025-01-01T12:00:00.000Z"
}json
{
"title": "Title text",
"description": "Description text",
"url": "https://example.com",
"color": 5763719,
"fields": [
{"name": "Field 1", "value": "Value 1", "inline": true}
],
"author": {"name": "Author", "icon_url": "https://..."},
"footer": {"text": "Footer text"},
"thumbnail": {"url": "https://..."},
"image": {"url": "https://..."},
"timestamp": "2025-01-01T12:00:00.000Z"
}Guidelines
注意事项
- Rate limits: 30 requests per 60 seconds per webhook
- Message limit: 2000 characters for content
- Embed limits: Max 10 embeds, 6000 total characters
- File limits: Max 8MB per file (50MB with Nitro boost)
- Security: Treat webhook URLs like passwords
- 频率限制:每个Webhook每分钟最多30次请求
- 消息长度限制:内容最多2000字符
- 嵌入内容限制:最多10个嵌入内容,总字符数不超过6000
- 文件大小限制:单文件最大8MB(开通Nitro会员后为50MB)
- 安全提示:将Webhook URL视为密码一样妥善保管