configure-discord

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Configure Discord Notifications

配置Discord通知

Set up Discord notifications so OMC can ping you when sessions end, need input, or complete background tasks.
设置Discord通知,以便OMC在会话结束、需要输入或完成后台任务时提醒你。

How This Skill Works

该技能的工作原理

This is an interactive, natural-language configuration skill. Walk the user through setup by asking questions with AskUserQuestion. Write the result to
~/.claude/.omc-config.json
.
这是一个交互式的自然语言配置技能。通过AskUserQuestion提问引导用户完成设置,并将结果写入
~/.claude/.omc-config.json

Step 1: Detect Existing Configuration

步骤1:检测现有配置

bash
CONFIG_FILE="$HOME/.claude/.omc-config.json"

if [ -f "$CONFIG_FILE" ]; then
  # Check for existing discord config
  HAS_DISCORD=$(jq -r '.notifications.discord.enabled // false' "$CONFIG_FILE" 2>/dev/null)
  HAS_DISCORD_BOT=$(jq -r '.notifications["discord-bot"].enabled // false' "$CONFIG_FILE" 2>/dev/null)
  WEBHOOK_URL=$(jq -r '.notifications.discord.webhookUrl // empty' "$CONFIG_FILE" 2>/dev/null)
  MENTION=$(jq -r '.notifications.discord.mention // empty' "$CONFIG_FILE" 2>/dev/null)

  if [ "$HAS_DISCORD" = "true" ] || [ "$HAS_DISCORD_BOT" = "true" ]; then
    echo "EXISTING_CONFIG=true"
    echo "WEBHOOK_CONFIGURED=$HAS_DISCORD"
    echo "BOT_CONFIGURED=$HAS_DISCORD_BOT"
    [ -n "$WEBHOOK_URL" ] && echo "WEBHOOK_URL=$WEBHOOK_URL"
    [ -n "$MENTION" ] && echo "MENTION=$MENTION"
  else
    echo "EXISTING_CONFIG=false"
  fi
else
  echo "NO_CONFIG_FILE"
fi
If existing config is found, show the user what's currently configured and ask if they want to update or reconfigure.
bash
CONFIG_FILE="$HOME/.claude/.omc-config.json"

if [ -f "$CONFIG_FILE" ]; then
  # 检查是否存在Discord配置
  HAS_DISCORD=$(jq -r '.notifications.discord.enabled // false' "$CONFIG_FILE" 2>/dev/null)
  HAS_DISCORD_BOT=$(jq -r '.notifications["discord-bot"].enabled // false' "$CONFIG_FILE" 2>/dev/null)
  WEBHOOK_URL=$(jq -r '.notifications.discord.webhookUrl // empty' "$CONFIG_FILE" 2>/dev/null)
  MENTION=$(jq -r '.notifications.discord.mention // empty' "$CONFIG_FILE" 2>/dev/null)

  if [ "$HAS_DISCORD" = "true" ] || [ "$HAS_DISCORD_BOT" = "true" ]; then
    echo "EXISTING_CONFIG=true"
    echo "WEBHOOK_CONFIGURED=$HAS_DISCORD"
    echo "BOT_CONFIGURED=$HAS_DISCORD_BOT"
    [ -n "$WEBHOOK_URL" ] && echo "WEBHOOK_URL=$WEBHOOK_URL"
    [ -n "$MENTION" ] && echo "MENTION=$MENTION"
  else
    echo "EXISTING_CONFIG=false"
  fi
else
  echo "NO_CONFIG_FILE"
fi
如果检测到现有配置,向用户展示当前配置内容,并询问是否要更新或重新配置。

Step 2: Choose Discord Method

步骤2:选择Discord配置方式

Use AskUserQuestion:
Question: "How would you like to send Discord notifications?"
Options:
  1. Webhook (Recommended) - Create a webhook in your Discord channel. Simple, no bot needed. Just paste the URL.
  2. Bot API - Use a Discord bot token + channel ID. More flexible, requires a bot application.
使用AskUserQuestion:
问题: "你希望通过哪种方式发送Discord通知?"
选项:
  1. Webhook(推荐) - 在你的Discord频道中创建一个webhook。操作简单,无需机器人,只需粘贴URL即可。
  2. Bot API - 使用Discord机器人令牌+频道ID。灵活性更高,但需要创建机器人应用。

Step 3A: Webhook Setup

步骤3A:Webhook设置

If user chose Webhook:
Use AskUserQuestion:
Question: "Paste your Discord webhook URL. To create one: Server Settings > Integrations > Webhooks > New Webhook > Copy URL"
The user will type their webhook URL in the "Other" field.
Validate the URL:
  • Must start with
    https://discord.com/api/webhooks/
    or
    https://discordapp.com/api/webhooks/
  • If invalid, explain the format and ask again
如果用户选择Webhook:
使用AskUserQuestion:
问题: "粘贴你的Discord webhook URL。创建方式:服务器设置 > 集成 > Webhooks > 新建Webhook > 复制URL"
用户将在“其他”字段中输入他们的webhook URL。
验证 URL:
  • 必须以
    https://discord.com/api/webhooks/
    https://discordapp.com/api/webhooks/
    开头
  • 如果无效,说明格式要求并重新询问

Step 3B: Bot API Setup

步骤3B:Bot API设置

If user chose Bot API:
Ask two questions:
  1. "Paste your Discord bot token" - From discord.com/developers > Your App > Bot > Token
  2. "Paste the channel ID" - Right-click channel > Copy Channel ID (requires Developer Mode)
如果用户选择Bot API:
提出两个问题:
  1. "粘贴你的Discord机器人令牌" - 来自discord.com/developers > 你的应用 > Bot > Token
  2. "粘贴频道ID" - 右键点击频道 > 复制频道ID(需要开启开发者模式)

Step 4: Configure Mention (User Ping)

步骤4:配置提及(用户提醒)

Use AskUserQuestion:
Question: "Would you like notifications to mention (ping) someone?"
Options:
  1. Yes, mention a user - Tag a specific user by their Discord user ID
  2. Yes, mention a role - Tag a role by its role ID
  3. No mentions - Just post the message without pinging anyone
使用AskUserQuestion:
问题: "你希望通知中提及(@)某人吗?"
选项:
  1. 是,提及用户 - 通过Discord用户ID标记特定用户
  2. 是,提及角色 - 通过角色ID标记某个角色
  3. 不提及 - 仅发送消息,不提醒任何人

If user wants to mention a user:

如果用户希望提及用户:

Ask: "What is the Discord user ID to mention? (Right-click user > Copy User ID, requires Developer Mode)"
The mention format is:
<@USER_ID>
(e.g.,
<@1465264645320474637>
)
询问:"要提及的Discord用户ID是什么?(右键点击用户 > 复制用户ID,需要开启开发者模式)"
提及格式为:
<@USER_ID>
(例如:
<@1465264645320474637>

If user wants to mention a role:

如果用户希望提及角色:

Ask: "What is the Discord role ID to mention? (Server Settings > Roles > right-click role > Copy Role ID)"
The mention format is:
<@&ROLE_ID>
(e.g.,
<@&123456789>
)
询问:"要提及的Discord角色ID是什么?(服务器设置 > 角色 > 右键点击角色 > 复制角色ID)"
提及格式为:
<@&ROLE_ID>
(例如:
<@&123456789>

Step 5: Configure Events

步骤5:配置触发事件

Use AskUserQuestion with multiSelect:
Question: "Which events should trigger Discord notifications?"
Options (multiSelect: true):
  1. Session end (Recommended) - When a Claude session finishes
  2. Input needed - When Claude is waiting for your response (great for long-running tasks)
  3. Session start - When a new session begins
  4. Session continuing - When a persistent mode keeps the session alive
Default selection: session-end + ask-user-question.
使用支持多选的AskUserQuestion:
问题: "哪些事件应该触发Discord通知?"
选项(多选:是):
  1. 会话结束(推荐) - 当Claude会话完成时
  2. 需要输入 - 当Claude等待你的响应时(适合长时间运行的任务)
  3. 会话开始 - 当新会话启动时
  4. 会话持续 - 当持久化模式保持会话活跃时
默认选择:会话结束 + 需要用户输入。

Step 6: Optional Username Override

步骤6:可选的用户名自定义

Use AskUserQuestion:
Question: "Custom bot display name? (Shows as the webhook sender name in Discord)"
Options:
  1. OMC (default) - Display as "OMC"
  2. Claude Code - Display as "Claude Code"
  3. Custom - Enter a custom name
使用AskUserQuestion:
问题: "自定义机器人显示名称?(在Discord中显示为webhook发送者名称)"
选项:
  1. OMC(默认) - 显示为"OMC"
  2. Claude Code - 显示为"Claude Code"
  3. 自定义 - 输入自定义名称

Step 7: Write Configuration

步骤7:写入配置

Read the existing config, merge the new Discord settings, and write back:
bash
CONFIG_FILE="$HOME/.claude/.omc-config.json"
mkdir -p "$(dirname "$CONFIG_FILE")"

if [ -f "$CONFIG_FILE" ]; then
  EXISTING=$(cat "$CONFIG_FILE")
else
  EXISTING='{}'
fi
读取现有配置,合并新的Discord设置,然后写回:
bash
CONFIG_FILE="$HOME/.claude/.omc-config.json"
mkdir -p "$(dirname "$CONFIG_FILE")"

if [ -f "$CONFIG_FILE" ]; then
  EXISTING=$(cat "$CONFIG_FILE")
else
  EXISTING='{}'
fi

For Webhook method:

对于Webhook方式:

Build the notifications object with the collected values and merge into
.omc-config.json
using jq:
bash
undefined
使用jq构建包含收集到的值的notifications对象,并合并到
.omc-config.json
中:
bash
undefined

WEBHOOK_URL, MENTION, USERNAME are collected from user

WEBHOOK_URL、MENTION、USERNAME为从用户处收集的值

EVENTS is the list of enabled events

EVENTS为启用的事件列表

echo "$EXISTING" | jq
--arg url "$WEBHOOK_URL"
--arg mention "$MENTION"
--arg username "$USERNAME"
'.notifications = (.notifications // {enabled: true}) | .notifications.enabled = true | .notifications.discord = { enabled: true, webhookUrl: $url, mention: (if $mention == "" then null else $mention end), username: (if $username == "" then null else $username end) }' > "$CONFIG_FILE"
undefined
echo "$EXISTING" | jq
--arg url "$WEBHOOK_URL"
--arg mention "$MENTION"
--arg username "$USERNAME"
'.notifications = (.notifications // {enabled: true}) | .notifications.enabled = true | .notifications.discord = { enabled: true, webhookUrl: $url, mention: (if $mention == "" then null else $mention end), username: (if $username == "" then null else $username end) }' > "$CONFIG_FILE"
undefined

For Bot API method:

对于Bot API方式:

bash
echo "$EXISTING" | jq \
  --arg token "$BOT_TOKEN" \
  --arg channel "$CHANNEL_ID" \
  --arg mention "$MENTION" \
  '.notifications = (.notifications // {enabled: true}) |
   .notifications.enabled = true |
   .notifications["discord-bot"] = {
     enabled: true,
     botToken: $token,
     channelId: $channel,
     mention: (if $mention == "" then null else $mention end)
   }' > "$CONFIG_FILE"
bash
echo "$EXISTING" | jq \
  --arg token "$BOT_TOKEN" \
  --arg channel "$CHANNEL_ID" \
  --arg mention "$MENTION" \
  '.notifications = (.notifications // {enabled: true}) |
   .notifications.enabled = true |
   .notifications["discord-bot"] = {
     enabled: true,
     botToken: $token,
     channelId: $channel,
     mention: (if $mention == "" then null else $mention end)
   }' > "$CONFIG_FILE"

Add event-specific config if user didn't select all events:

如果用户未选择所有事件,添加特定事件配置:

For each event NOT selected, disable it:
bash
undefined
对于每个未被选中的事件,将其禁用:
bash
undefined

Example: disable session-start if not selected

示例:如果未选择session-start,则禁用它

echo "$(cat "$CONFIG_FILE")" | jq
'.notifications.events = (.notifications.events // {}) | .notifications.events["session-start"] = {enabled: false}' > "$CONFIG_FILE"
undefined
echo "$(cat "$CONFIG_FILE")" | jq
'.notifications.events = (.notifications.events // {}) | .notifications.events["session-start"] = {enabled: false}' > "$CONFIG_FILE"
undefined

Step 8: Test the Configuration

步骤8:测试配置

After writing config, offer to send a test notification:
Use AskUserQuestion:
Question: "Send a test notification to verify the setup?"
Options:
  1. Yes, test now (Recommended) - Send a test message to your Discord channel
  2. No, I'll test later - Skip testing
写入配置后,提供发送测试通知的选项:
使用AskUserQuestion:
问题: "发送测试通知以验证设置是否成功?"
选项:
  1. 是,立即测试(推荐) - 向你的Discord频道发送测试消息
  2. 否,稍后自行测试 - 跳过测试

If testing:

如果进行测试:

bash
undefined
bash
undefined

For webhook:

对于webhook:

curl -s -o /dev/null -w "%{http_code}"
-H "Content-Type: application/json"
-d "{"content": "${MENTION:+$MENTION\n}OMC test notification - Discord is configured!"}"
"$WEBHOOK_URL"

Report success or failure. If it fails, help the user debug (check URL, permissions, etc.).
curl -s -o /dev/null -w "%{http_code}"
-H "Content-Type: application/json"
-d "{"content": "${MENTION:+$MENTION\n}OMC test notification - Discord is configured!"}"
"$WEBHOOK_URL"

报告测试成功或失败。如果失败,帮助用户排查问题(检查URL、权限等)。

Step 9: Confirm

步骤9:确认

Display the final configuration summary:
Discord Notifications Configured!

  Method:   Webhook / Bot API
  Mention:  <@1465264645320474637> (or "none")
  Events:   session-end, ask-user-question
  Username: OMC

Config saved to: ~/.claude/.omc-config.json

You can also set these via environment variables:
  OMC_DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/...
  OMC_DISCORD_MENTION=<@1465264645320474637>

To reconfigure: /oh-my-claudecode:configure-discord
To configure Telegram: /oh-my-claudecode:configure-telegram
显示最终配置摘要:
Discord通知已配置完成!

  方式:   Webhook / Bot API
  提及:  <@1465264645320474637>(或"无")
  事件:   session-end, ask-user-question
  用户名: OMC

配置已保存至: ~/.claude/.omc-config.json

你也可以通过环境变量设置这些配置:
  OMC_DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/...
  OMC_DISCORD_MENTION=<@1465264645320474637>

重新配置:/oh-my-claudecode:configure-discord
配置Telegram:/oh-my-claudecode:configure-telegram

Environment Variable Alternative

环境变量替代方案

Users can skip this wizard entirely by setting env vars in their shell profile:
Webhook method:
bash
export OMC_DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/..."
export OMC_DISCORD_MENTION="<@1465264645320474637>"  # optional
Bot API method:
bash
export OMC_DISCORD_NOTIFIER_BOT_TOKEN="your-bot-token"
export OMC_DISCORD_NOTIFIER_CHANNEL="your-channel-id"
export OMC_DISCORD_MENTION="<@1465264645320474637>"  # optional
Env vars are auto-detected by the notification system without needing
.omc-config.json
.
用户可以完全跳过此向导,直接在shell配置文件中设置环境变量:
Webhook方式:
bash
export OMC_DISCORD_WEBHOOK_URL="https://discord.com/api/webhooks/..."
export OMC_DISCORD_MENTION="<@1465264645320474637>"  # 可选
Bot API方式:
bash
export OMC_DISCORD_NOTIFIER_BOT_TOKEN="your-bot-token"
export OMC_DISCORD_NOTIFIER_CHANNEL="your-channel-id"
export OMC_DISCORD_MENTION="<@1465264645320474637>"  # 可选
通知系统会自动检测环境变量,无需依赖
.omc-config.json