Build Compose - Free Discord Message Builder
集成与机器人 5 min read Updated: 2026-11-10

如何创建、配置与发送 Discord Webhook(分步实战指南)

熟练掌握 Discord Webhook,无需常驻运行复杂的机器人服务进程,即可轻松发送自动化通知、GitHub 告警、全服广播及自定义机器人消息。

#Webhooks #Automations #discord.js #Python #HTTP POST

实时测试 Webhook

使用我们的交互式 Webhook 发送工具,一键推送真实 Embed、自定义头像及带格式的富文本消息。

打开 Webhook 发送工具
1

什么是 Discord Webhook?

Discord Webhook 是一种自动化的 HTTP 端点,允许外部第三方服务、脚本和后端服务器直接向指定的 Discord 频道推送消息与富文本 Embed。与完整机器人不同,Webhook 不需要配置 Bot Token、维护 WebSocket 长连接,也无需任何服务器托管成本。

2

如何在 Discord 中创建 Webhook

创建步骤:1. 打开 Discord 服务器设置,或右键点击任意文字频道并选择“编辑频道”;2. 点击左侧菜单中的“整合”;3. 选择“Webhook”并点击“新建 Webhook”;4. 为其指定默认名称与头像,随后点击“复制 Webhook URL”。

安全警告

绝不要将 Webhook URL 提交到公开代码仓库或分享给不可信的人。任何拿到该链接的人都可以向对应频道发送消息。一旦泄露,请立即在 Discord 中将其删除以注销访问权限。

3

通过代码发送消息与富文本 Embed

Webhook 接收携带 JSON 请求体的标准 HTTP POST 请求。在每次调用时,你都可以自由覆盖默认的用户名和头像,并最多同时附带 10 个 Embed 或 Components V2 组件块。

Node.js / fetch
const webhookUrl = 'https://discord.com/api/webhooks/123456789/token';

await fetch(webhookUrl, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    username: 'Alert Bot',
    avatar_url: 'https://i.imgur.com/4M34hi2.png',
    content: '🚨 New server alert!',
    embeds: [{
      title: 'Server Update',
      description: 'Maintenance completed successfully.',
      color: 0x57F287
    }]
  })
});
Python (requests)
import requests

webhook_url = "https://discord.com/api/webhooks/123456789/token"
payload = {
    "username": "Server Notifier",
    "content": "Hello Discord from Python!",
    "embeds": [{
        "title": "Automated Report",
        "description": "Backup completed without errors.",
        "color": 5763719
    }]
}

response = requests.post(webhook_url, json=payload)
print(response.status_code)
4

使用 BuildCompose 测试与调试 Webhook

在正式部署业务代码前,推荐使用 BuildCompose 的 Webhook 发送与测试工具。粘贴你的 Webhook URL,可视化定制消息或 Embed,一键发送并实时核对实际生成的 JSON 数据包。

常见问题

相关指南