Skip to content

Discord

Discord 驱动器通过 Discord 网关(Bot Token)接收消息,并支持通过 WebhookBot 两种方式发送消息。

准备工作

  1. Discord 开发者门户 创建一个 Bot 应用。
  2. Bot 页面中启用 Message Content Intent(消息内容权限)。
  3. 复制 Bot Token。
  4. 如需 Webhook 发送:在频道设置中创建 Webhook 并复制其 URL。
  5. 将 Bot 邀请至你的服务器,确保其拥有 Read MessagesSend Messages 权限。

配置项

config.jsondiscord.<实例ID> 下添加:

是否必填默认值说明
bot_token否*Discord Bot Token,接收消息和 bot 发送模式均需此项
send_methodwebhook"webhook""bot"
webhook_url否*Webhook URL,send_method"webhook" 时必填
max_file_size8388608(8 MB)发送附件时单个文件的最大字节数

* bot_token(用于接收)和 webhook_url(用于发送)至少需要提供其中一个。

json
{
  "discord": {
    "dc_main": {
      "bot_token": "your_bot_token",
      "send_method": "webhook",
      "webhook_url": "https://discord.com/api/webhooks/ID/TOKEN",
      "max_file_size": 8388608
    }
  }
}

发送模式

webhook(默认)

通过 Discord Webhook URL 发送消息。支持通过规则 msg 配置中的 webhook_titlewebhook_avatar 为每条消息设置自定义显示名和头像。

json
"msg": {
  "msg_format": "{msg}",
  "webhook_title": "{user} @ {from}",
  "webhook_avatar": "{user_avatar}"
}

bot

通过 Bot 自身发送消息,需要提供 bot_token。不支持每条消息自定义用户名和头像。

规则频道键

rules.jsonchannelsfrom/to 下使用:

说明
server_idDiscord 服务器(Guild)ID
channel_idDiscord 频道 ID
json
{
  "dc_main": {
    "server_id": "1061629481267245086",
    "channel_id": "1269706305661309030"
  }
}

额外 msg 键

以下键可放在规则的 msg 块中,仅在 send_method"webhook" 时被 Discord 驱动器使用:

说明
webhook_titleWebhook 消息上显示的用户名
webhook_avatarWebhook 消息上显示的头像 URL

两者均支持与 msg_format 相同的模板变量。

注意事项

  • Bot 发送的消息不会被再次桥接(Webhook 回显不会触发事件)。
  • 文件会被下载后通过 multipart 表单重新上传。若文件超过 max_file_size,其 URL 将以文字形式附加到消息中。