Added discord support and openAI gpt-5-mini#1127
Added discord support and openAI gpt-5-mini#1127Chutengli wants to merge 3 commits intoNVIDIA:mainfrom
Conversation
📝 WalkthroughWalkthroughThis 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
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)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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_idandresume_gateway_urlfrom 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
📒 Files selected for processing (9)
bin/lib/onboard.jsbin/nemoclaw.jsdocs/reference/commands.mdnemoclaw-blueprint/policies/openclaw-sandbox.yamlnemoclaw-blueprint/policies/presets/discord.yamlscripts/discord-bridge.jsscripts/start-services.shtest/onboard.test.jstest/runner.test.js
| 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; | ||
| } |
There was a problem hiding this comment.
Discriminator display may show outdated format; model name appears stale.
-
Line 280: Discord deprecated discriminators in 2023. Most users now have discriminator
"0", causingbotTagto display as"username#0". Consider displaying just the username for modern accounts. -
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.
| 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.
|
✨ Thanks for submitting this pull request, which proposes a way to add new features (Discord support) and providers to NemoClaw. Possibly related open issues:
|
Summary
Signed-off-by: Your Name your-email@example.com
Related Issue
Changes
Type of Change
Testing
npx prek run --all-filespasses (or equivalentlymake check).npm testpasses.make docsbuilds without warnings. (for doc-only changes)Checklist
General
Code Changes
npx prek run --all-filesauto-fixes formatting (ormake formatfor targeted runs).Doc Changes
update-docsagent skill to draft changes while complying with the style guide. For example, prompt your agent with "/update-docscatch up the docs for the new changes I made in this PR."Summary by CodeRabbit
New Features
Documentation
Configuration