Skip to content

fix(discord): send online presence on ready when no custom presence is configured#31333

Closed
Sid-Qin wants to merge 1 commit intoopenclaw:mainfrom
Sid-Qin:fix/discord-bot-presence-31260
Closed

fix(discord): send online presence on ready when no custom presence is configured#31333
Sid-Qin wants to merge 1 commit intoopenclaw:mainfrom
Sid-Qin:fix/discord-bot-presence-31260

Conversation

@Sid-Qin
Copy link
Copy Markdown
Contributor

@Sid-Qin Sid-Qin commented Mar 2, 2026

Summary

  • Problem: Discord bot appears offline (gray status dot) despite functioning correctly. Messages send and receive fine, but the bot never shows as "online" in the Discord user list.
  • Why it matters: Users see the bot as offline and may think it's broken, even though it's fully operational.
  • What changed: resolveDiscordPresenceUpdate now returns a minimal { status: "online" } presence object when neither activity nor status is configured, instead of returning null. This ensures DiscordStatusReadyListener always calls gateway.updatePresence() on connect.
  • What did NOT change: Custom presence configuration (activity text, status, activity type, streaming URL) works exactly the same. Only the "no config" default changed from "no presence update" to "online".

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

  1. Discord bots now appear "online" (green status dot) by default when connected, even without explicit presence configuration.
  2. No config changes required — this is a sensible default change.

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No (presence update was already sent when configured; now it also fires when unconfigured)
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: macOS / Linux
  • Runtime: Node.js 22+
  • Integration: Discord (any bot token)

Steps

  1. Configure a Discord bot without activity or status fields
  2. Start gateway
  3. Check bot status in Discord

Expected

  • Bot shows as "online" (green)

Actual

  • Before: Bot shows as "offline" (gray)
  • After: Bot shows as "online" (green)

Evidence

  • Failing test/log before + passing after

New test file presence.test.ts with 6 test cases:

  • Returns online presence when no config provided
  • Uses configured status
  • Includes activity when configured
  • Uses custom activity type by default
  • Respects explicit activityType
  • Sets streaming URL for type 1

Human Verification (required)

  • Verified scenarios: no config (default online); custom status (dnd, idle); activity text with custom type; streaming URL
  • Edge cases checked: empty strings for activity/status (treated as unconfigured); whitespace-only values
  • What you did not verify: Live Discord bot with actual gateway connection

Compatibility / Migration

  • Backward compatible? Yes — bots with explicit presence config are unaffected. Bots without config will now appear online instead of offline.
  • Config/env changes? No
  • Migration needed? No

Failure Recovery (if this breaks)

  • How to disable/revert: Change the return value back to null in resolveDiscordPresenceUpdate when no config is set
  • Files to restore: src/discord/monitor/presence.ts

Risks and Mitigations

  • Risk: Users who intentionally want the bot to appear offline would now see it as online
    • Mitigation: They can set status: "invisible" explicitly to hide the bot. The previous behavior was undocumented and almost certainly unintentional.

…s configured

When neither activity nor status was configured, resolveDiscordPresenceUpdate
returned null. The ReadyListener skipped the updatePresence call, so
Discord never received a presence update and showed the bot as offline.

Return a minimal { status: "online" } presence instead of null so the
gateway always sends a presence update on connect.

Closes openclaw#31260

Made-with: Cursor
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9e151b1ba2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


if (!hasActivity && !hasStatus) {
return null;
return { since: null, activities: [], status: "online", afk: false };
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Update legacy tests for default online presence

This change makes resolveDiscordPresenceUpdate({}) return a non-null object, but src/discord/monitor/monitor.test.ts:714-716 still asserts the no-config case is null, so the Discord monitor test suite becomes internally inconsistent and will fail when run (pnpm test). Please update or remove that legacy assertion so CI reflects the new behavior instead of flagging this as a regression.

Useful? React with 👍 / 👎.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 2, 2026

Greptile Summary

This PR fixes the Discord bot offline status issue by ensuring a presence update is sent even when no custom presence configuration exists. The change is minimal and well-executed: resolveDiscordPresenceUpdate now returns { status: "online", activities: [] } instead of null when neither activity nor status is configured.

  • Changed one line in src/discord/monitor/presence.ts (line 24) from returning null to returning a default online presence
  • Added comprehensive test coverage with 6 test cases covering default behavior, custom status, activities, and edge cases
  • The fix ensures DiscordStatusReadyListener.handle() in provider.ts always calls gateway.updatePresence() on connect, making the bot appear online
  • Backward compatible: bots with explicit presence configuration are completely unaffected
  • Edge cases properly handled: empty strings, whitespace-only values, and undefined/null configs are all treated as "no config"

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change is a simple one-line fix that correctly addresses the stated problem. The implementation is clean, the test coverage is comprehensive (6 test cases), and the logic properly handles edge cases. The change is backward compatible and doesn't introduce any new dependencies or security concerns. No logical errors, type safety issues, or edge case problems were found.
  • No files require special attention

Last reviewed commit: 9e151b1

@thewilloftheshadow
Copy link
Copy Markdown
Member

Superseded by #33277 (consolidated presence/health work). Please follow the new PR.

@thewilloftheshadow
Copy link
Copy Markdown
Member

Superceded by existing commits on main

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

Labels

channel: discord Channel integration: discord size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Discord bot shows as offline despite being functional

2 participants