Skip to content

Added discord support and openAI gpt-5-mini#1127

Open
Chutengli wants to merge 3 commits intoNVIDIA:mainfrom
Chutengli:main
Open

Added discord support and openAI gpt-5-mini#1127
Chutengli wants to merge 3 commits intoNVIDIA:mainfrom
Chutengli:main

Conversation

@Chutengli
Copy link
Copy Markdown

@Chutengli Chutengli commented Mar 30, 2026

Summary

Signed-off-by: Your Name your-email@example.com

Related Issue

Changes

Type of Change

  • Code change for a new feature, bug fix, or refactor.
  • Code change with doc updates.
  • Doc only. Prose changes without code sample modifications.
  • Doc only. Includes code sample changes.

Testing

  • npx prek run --all-files passes (or equivalently make check).
  • npm test passes.
  • make docs builds without warnings. (for doc-only changes)

Checklist

General

Code Changes

  • Formatters applied — npx prek run --all-files auto-fixes formatting (or make format for targeted runs).
  • Tests added or updated for new or changed behavior.
  • No secrets, API keys, or credentials committed.
  • Doc pages updated for any user-facing behavior changes (new commands, changed defaults, new features, bug fixes that contradict existing docs).

Doc Changes

  • Follows the style guide. Try running the update-docs agent skill to draft changes while complying with the style guide. For example, prompt your agent with "/update-docs catch up the docs for the new changes I made in this PR."
  • New pages include SPDX license header and frontmatter, if creating a new page.
  • Cross-references and links verified.

Summary by CodeRabbit

  • New Features

    • Added Discord bot bridge to interact with the OpenClaw agent via Discord messaging.
    • Added OpenAI GPT-5 model support with updated inference compatibility configuration.
  • Documentation

    • Updated command reference to include Discord bridge setup and token requirements.
  • Configuration

    • Service startup now activates when either Telegram or Discord credentials are provided.
    • Added network policies for Discord API endpoints.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 30, 2026

📝 Walkthrough

Walkthrough

This pull request introduces Discord bot integration alongside the existing Telegram bridge. A new Discord bridge script establishes WebSocket connections to Discord's gateway, handles message events, executes OpenClaw agents, and posts results back to Discord channels. Supporting changes include service orchestration updates, network policies for Discord endpoints, and inference compatibility handling for GPT-5 models.

Changes

Cohort / File(s) Summary
Discord Bridge Implementation
scripts/discord-bridge.js
New 329-line executable implementing Discord gateway WebSocket client with message handling, agent execution via SSH, and response posting with chunking logic.
Service Orchestration
bin/nemoclaw.js, scripts/start-services.sh
Extended startup/stop logic to conditionally manage discord-bridge service alongside telegram-bridge and cloudflared; now triggers when either DISCORD_BOT_TOKEN or TELEGRAM_BOT_TOKEN is present.
Network Policy Configuration
nemoclaw-blueprint/policies/openclaw-sandbox.yaml, nemoclaw-blueprint/policies/presets/discord.yaml
Added REST/HTTPS and TLS-enforced policies for Discord endpoints (channels.discord.dm:443 and discord.com:443) with explicit GET/POST allow rules.
Inference Compatibility
bin/lib/onboard.js, test/onboard.test.js
Set inferenceCompat: { supportsStore: false } for OpenAI GPT-5 models via regex pattern match; added corresponding unit tests to validate behavior for GPT-5 variants and non-matching models.
Testing & Documentation
test/runner.test.js, docs/reference/commands.md
Added regression test validating Discord bridge startup validation; updated nemoclaw start documentation to describe Discord bridge and dual token requirements.

Sequence Diagram(s)

sequenceDiagram
    participant Discord as Discord Gateway
    participant Bot as discord-bridge.js
    participant SSH as SSH Client
    participant Sandbox as OpenClaw Sandbox
    participant Response as Discord Channel

    Discord->>Bot: MESSAGE_CREATE event (WebSocket)
    Bot->>Bot: Validate channel & extract command
    Bot->>Response: Post typing indicator
    Bot->>SSH: Generate ssh-config via openshell
    Bot->>SSH: Spawn ssh with agent command
    SSH->>Sandbox: Execute nemoclaw-start openclaw agent
    Sandbox->>SSH: Stream stdout/stderr
    SSH->>Bot: Return exit code + output
    Bot->>Bot: Parse & chunk response (<1900 chars)
    Bot->>Response: POST Discord message chunks (reply)
    Discord-->>Bot: Message posted (REST API response)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A Discord bridge now hops into the fray,
Bringing messages from bots throughout the day—
While GPT-5 learns to store not its state,
Our services dance, both timely and great!
One config to rule them, one token per bot—
The warren expands with just what we've got! 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures two major features added in the changeset: Discord bot bridge support and OpenAI gpt-5 model inference compatibility configuration.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
scripts/discord-bridge.js (1)

304-317: Consider implementing session resume for reliability.

The reconnect logic correctly uses exponential backoff, but always performs a fresh IDENTIFY (op 2) rather than RESUME (op 6). This means messages sent during the reconnect window may be lost.

For a bridge that may handle important messages, consider storing session_id and resume_gateway_url from the READY event and using op 6 RESUME on reconnection to receive missed events.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/discord-bridge.js` around lines 304 - 317, Save session_id and
resume_gateway_url when handling the READY event and track last sequence (seq)
for incoming events; in connectGateway()'s reconnect path (the ws "close"
handler where reconnectDelayMs, stopHeartbeat() and reconnect are used), if a
stored session_id and resume_gateway_url exist attempt a RESUME (op 6) payload
containing token, session_id and last seq instead of sending an IDENTIFY (op 2);
if Discord responds with an invalid session, fall back to IDENTIFY, clear
session_id/resume_gateway_url, and continue normal IDENTIFY flow; ensure the
reconnect logic uses resume_gateway_url as the connect endpoint when present and
preserves session_id/seq across reconnect attempts.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/discord-bridge.js`:
- Around line 278-295: Update the READY handling to avoid showing deprecated
discriminators and to use a current model identifier: when payload.t === "READY"
build botTag from payload.d.user.username alone if payload.d.user.discriminator
is "0" or falsy (otherwise keep username#discriminator) so usernames don’t show
"username#0"; also stop printing the hardcoded
"nvidia/nemotron-3-super-120b-a12b" and instead reference a single
source-of-truth model variable (e.g., MODEL or MODEL_NAME / process.env.MODEL)
so the printed "Model:" line reflects the configured model for the bridge.

---

Nitpick comments:
In `@scripts/discord-bridge.js`:
- Around line 304-317: Save session_id and resume_gateway_url when handling the
READY event and track last sequence (seq) for incoming events; in
connectGateway()'s reconnect path (the ws "close" handler where
reconnectDelayMs, stopHeartbeat() and reconnect are used), if a stored
session_id and resume_gateway_url exist attempt a RESUME (op 6) payload
containing token, session_id and last seq instead of sending an IDENTIFY (op 2);
if Discord responds with an invalid session, fall back to IDENTIFY, clear
session_id/resume_gateway_url, and continue normal IDENTIFY flow; ensure the
reconnect logic uses resume_gateway_url as the connect endpoint when present and
preserves session_id/seq across reconnect attempts.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cc817edc-95ea-47f4-9d4a-42415c9c0958

📥 Commits

Reviewing files that changed from the base of the PR and between 2cb6ed8 and 8853ad2.

📒 Files selected for processing (9)
  • bin/lib/onboard.js
  • bin/nemoclaw.js
  • docs/reference/commands.md
  • nemoclaw-blueprint/policies/openclaw-sandbox.yaml
  • nemoclaw-blueprint/policies/presets/discord.yaml
  • scripts/discord-bridge.js
  • scripts/start-services.sh
  • test/onboard.test.js
  • test/runner.test.js

Comment on lines +278 to +295
if (payload.t === "READY") {
botUserId = payload.d.user.id;
botTag = `${payload.d.user.username}#${payload.d.user.discriminator}`;
console.log("");
console.log(" ┌─────────────────────────────────────────────────────┐");
console.log(" │ NemoClaw Discord Bridge │");
console.log(" │ │");
console.log(` │ Bot: ${(botTag + " ").slice(0, 40)}│`);
console.log(" │ Sandbox: " + (SANDBOX + " ").slice(0, 40) + "│");
console.log(" │ Model: nvidia/nemotron-3-super-120b-a12b │");
console.log(" │ │");
console.log(" │ Messages are forwarded to the OpenClaw agent │");
console.log(" │ inside the sandbox. Run 'openshell term' in │");
console.log(" │ another terminal to monitor + approve egress. │");
console.log(" └─────────────────────────────────────────────────────┘");
console.log("");
return;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Discriminator display may show outdated format; model name appears stale.

  1. Line 280: Discord deprecated discriminators in 2023. Most users now have discriminator "0", causing botTag to display as "username#0". Consider displaying just the username for modern accounts.

  2. Line 287: Hardcoded model "nvidia/nemotron-3-super-120b-a12b" doesn't match the PR title mentioning "gpt-5-mini" support. This may be misleading or stale.

🔧 Proposed fix for discriminator handling
     if (payload.t === "READY") {
       botUserId = payload.d.user.id;
-      botTag = `${payload.d.user.username}#${payload.d.user.discriminator}`;
+      const disc = payload.d.user.discriminator;
+      botTag = disc && disc !== "0" ? `${payload.d.user.username}#${disc}` : payload.d.user.username;
       console.log("");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (payload.t === "READY") {
botUserId = payload.d.user.id;
botTag = `${payload.d.user.username}#${payload.d.user.discriminator}`;
console.log("");
console.log(" ┌─────────────────────────────────────────────────────┐");
console.log(" │ NemoClaw Discord Bridge │");
console.log(" │ │");
console.log(` │ Bot: ${(botTag + " ").slice(0, 40)}│`);
console.log(" │ Sandbox: " + (SANDBOX + " ").slice(0, 40) + "│");
console.log(" │ Model: nvidia/nemotron-3-super-120b-a12b │");
console.log(" │ │");
console.log(" │ Messages are forwarded to the OpenClaw agent │");
console.log(" │ inside the sandbox. Run 'openshell term' in │");
console.log(" │ another terminal to monitor + approve egress. │");
console.log(" └─────────────────────────────────────────────────────┘");
console.log("");
return;
}
if (payload.t === "READY") {
botUserId = payload.d.user.id;
const disc = payload.d.user.discriminator;
botTag = disc && disc !== "0" ? `${payload.d.user.username}#${disc}` : payload.d.user.username;
console.log("");
console.log(" ┌─────────────────────────────────────────────────────┐");
console.log(" │ NemoClaw Discord Bridge │");
console.log(" │ │");
console.log(` │ Bot: ${(botTag + " ").slice(0, 40)}│`);
console.log(" │ Sandbox: " + (SANDBOX + " ").slice(0, 40) + "│");
console.log(" │ Model: nvidia/nemotron-3-super-120b-a12b │");
console.log(" │ │");
console.log(" │ Messages are forwarded to the OpenClaw agent │");
console.log(" │ inside the sandbox. Run 'openshell term' in │");
console.log(" │ another terminal to monitor + approve egress. │");
console.log(" └─────────────────────────────────────────────────────┘");
console.log("");
return;
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/discord-bridge.js` around lines 278 - 295, Update the READY handling
to avoid showing deprecated discriminators and to use a current model
identifier: when payload.t === "READY" build botTag from payload.d.user.username
alone if payload.d.user.discriminator is "0" or falsy (otherwise keep
username#discriminator) so usernames don’t show "username#0"; also stop printing
the hardcoded "nvidia/nemotron-3-super-120b-a12b" and instead reference a single
source-of-truth model variable (e.g., MODEL or MODEL_NAME / process.env.MODEL)
so the printed "Model:" line reflects the configured model for the bridge.

@wscurran wscurran added enhancement: feature Use this label to identify requests for new capabilities in NemoClaw. enhancement: provider Use this label to identify requests to add a new AI provider to NemoClaw. Integration: Discord Use this label to identify Discord bot integration issues with NemoClaw. labels Apr 1, 2026
@wscurran
Copy link
Copy Markdown
Contributor

wscurran commented Apr 1, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement: feature Use this label to identify requests for new capabilities in NemoClaw. enhancement: provider Use this label to identify requests to add a new AI provider to NemoClaw. Integration: Discord Use this label to identify Discord bot integration issues with NemoClaw.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants