openclaw - ✅(Solved) Fix [Bug]: Discord setup: service file doesn't include DISCORD_BOT_TOKEN environment variable [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#67817Fetched 2026-04-17 08:29:20
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Timeline (top)
labeled ×2commented ×1cross-referenced ×1

When setting up Discord via the onboarding wizard, the setup flow instructs you to set DISCORD_BOT_TOKEN as an environment variable and configure the token as an env ref (--ref-source env). However, the generated systemd service file does not include this environment variable, causing the gateway service to fail to connect to Discord on restart.

Error Message

Service file should be populated with the DISCORD_BOT_TOKEN env var, or the setup docs/wizard should warn that env vars must be added manually to the service file.

Root Cause

When setting up Discord via the onboarding wizard, the setup flow instructs you to set DISCORD_BOT_TOKEN as an environment variable and configure the token as an env ref (--ref-source env). However, the generated systemd service file does not include this environment variable, causing the gateway service to fail to connect to Discord on restart.

Fix Action

Fixed

PR fix notes

PR #67881: fix(daemon): persist Discord env ref in service env

Description (problem / solution / changelog)

Summary

AI-assisted: Codex was used for investigation, implementation, and targeted validation. Testing: targeted local tests plus build/import-cycle checks; full repo-wide pnpm check / pnpm test were not rerun end-to-end. Session log not attached.

  • Problem: Discord onboarding can store channels.discord.token as an env-backed SecretRef, but daemon install did not carry that env var into the service environment.
  • Why it matters: after openclaw gateway restart under systemd/WSL2, the supervised gateway can lose the Discord bot token and fail to reconnect.
  • What changed: daemon install now copies the Discord default-account env-backed SecretRef into the managed service environment when the source env var is available at install time.
  • What did NOT change (scope boundary): auth-profile env refs, .env handling, non-env SecretRefs, non-Discord channel SecretRefs, and channel setup UX were left unchanged.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • 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

  • Closes #67817
  • Related #
  • This PR fixes a bug or regression

Root Cause (if applicable)

  • Root cause: buildGatewayInstallPlan() persisted durable env vars and auth-profile env refs, but it ignored the Discord default-account env-backed SecretRef already stored at channels.discord.token.
  • Missing detection / guardrail: there was no install-time bridge from the Discord default token SecretRef to the service-managed environment.
  • Contributing context (if known): Discord setup docs and onboarding allow DISCORD_BOT_TOKEN with --ref-source env, which works in the invoking shell but not after a supervised restart unless the service environment also gets that value.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: src/commands/daemon-install-helpers.test.ts
  • Scenario the test should lock in: a default Discord env-backed SecretRef should contribute DISCORD_BOT_TOKEN to the daemon install environment when that env var is present at install time.
  • Why this is the smallest reliable guardrail: the failure happens in install-plan generation before any actual systemd interaction, so the helper test isolates the exact bug without needing a full supervisor environment.
  • Existing test that already covers this (if any): adjacent auth-profile env-ref coverage already existed in the same file.
  • If no new test is added, why not: N/A

User-visible / Behavior Changes

  • openclaw gateway install / onboarding-driven daemon install now preserves a default Discord env-backed SecretRef (DISCORD_BOT_TOKEN) in the service environment when that env value is present during install.

Diagram (if applicable)

Before:
Discord onboarding stores env ref -> daemon install writes service env without DISCORD_BOT_TOKEN -> supervised restart loses token

After:
Discord onboarding stores env ref -> daemon install copies DISCORD_BOT_TOKEN into managed service env -> supervised restart keeps token

Security Impact (required)

  • New permissions/capabilities? (Yes/No) No
  • Secrets/tokens handling changed? (Yes/No) Yes
  • New/changed network calls? (Yes/No) No
  • Command/tool execution surface changed? (Yes/No) No
  • Data access scope changed? (Yes/No) No
  • If any Yes, explain risk + mitigation:
    • The install path now persists the Discord default-account env-backed SecretRef into the managed service environment, matching the existing install-time handling of other durable env-backed credentials. The change is limited to channels.discord.token with source: "env", skips unresolved values, and reuses the existing dangerous-env filtering.

Repro + Verification

Environment

  • OS: macOS (local validation), original issue reports Linux / WSL2
  • Runtime/container: Node 24.14.0 / pnpm 10.32.1 in validation checkout
  • Model/provider: N/A
  • Integration/channel (if any): Discord daemon install path
  • Relevant config (redacted): channels.discord.token = { source: "env", provider: "default", id: "DISCORD_BOT_TOKEN" }

Steps

  1. Configure Discord during onboarding using DISCORD_BOT_TOKEN with --ref-source env.
  2. Install or restart the gateway as a supervised daemon.
  3. Inspect the install plan / service environment or restart behavior.

Expected

  • The service-managed gateway still has access to DISCORD_BOT_TOKEN after restart.

Actual

  • Before this change, the install plan omitted DISCORD_BOT_TOKEN, so the supervised gateway could restart without the bot token.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios:
    • Added a focused failing test for the Discord env-backed SecretRef in buildGatewayInstallPlan() and confirmed it failed before the fix.
    • Re-ran the focused test after the fix and confirmed it passed.
    • Re-ran the full daemon-install-helpers, configure.daemon, and related daemon install command test files.
    • Re-ran pnpm build, pnpm check:import-cycles, and changed-file oxlint validation.
  • Edge cases checked:
    • Existing auth-profile env-ref behavior still passes unchanged.
    • Dangerous env var filtering remains in place.
    • Non-env SecretRefs remain excluded.
  • What you did not verify:
    • I did not run a full interactive Discord onboarding flow under real Linux/WSL2 systemd locally.
    • I did not rerun the full repo-wide pnpm check / pnpm test suites end-to-end.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.

Compatibility / Migration

  • Backward compatible? (Yes/No) Yes
  • Config/env changes? (Yes/No) No
  • Migration needed? (Yes/No) No
  • If yes, exact upgrade steps:

Risks and Mitigations

  • Risk:
    • Managed service installs now persist the Discord default token env ref when it is configured and resolvable at install time.
    • Mitigation:
      • The copy is limited to the documented default Discord token env-ref path, requires a present env value during install, and reuses the existing host-env danger filters.

Changed files

RAW_BUFFERClick to expand / collapse

Bug type

Crash (process/app exits or hangs)

Beta release blocker

No

Summary

When setting up Discord via the onboarding wizard, the setup flow instructs you to set DISCORD_BOT_TOKEN as an environment variable and configure the token as an env ref (--ref-source env). However, the generated systemd service file does not include this environment variable, causing the gateway service to fail to connect to Discord on restart.

Steps to reproduce

Run openclaw onboard and configure Discord with a bot token via env ref Restart the gateway via openclaw gateway restart Gateway fails to start.

Expected behavior

Service file should be populated with the DISCORD_BOT_TOKEN env var, or the setup docs/wizard should warn that env vars must be added manually to the service file.

Actual behavior

Gateway fails to start.

OpenClaw version

OpenClaw 2026.4.14 (323493f)

Operating system

Linux (WSL2)

Install method

No response

Model

anthropic/claude-sonnet-4.5

Provider / routing chain

openclaw -> gateway

Additional provider/model setup details

No response

Logs, screenshots, and evidence

Impact and severity

No response

Additional information

No response

extent analysis

TL;DR

The systemd service file needs to be updated to include the DISCORD_BOT_TOKEN environment variable for the gateway service to connect to Discord on restart.

Guidance

  • Verify that the DISCORD_BOT_TOKEN environment variable is set correctly in the environment where the systemd service file is generated.
  • Check the documentation for the onboarding wizard to see if there are any specific instructions for configuring environment variables in the systemd service file.
  • Manually add the DISCORD_BOT_TOKEN environment variable to the systemd service file to test if this resolves the issue.
  • Consider updating the setup wizard to include instructions for adding environment variables to the systemd service file or to automatically populate the service file with the required environment variables.

Example

No code snippet is provided as the issue does not contain sufficient information about the specific code or configuration files involved.

Notes

The solution may vary depending on the specific configuration and setup of the OpenClaw application and the systemd service file. Additionally, the issue may be resolved in a future version of OpenClaw, but this is not specified in the provided information.

Recommendation

Apply workaround: Manually add the DISCORD_BOT_TOKEN environment variable to the systemd service file, as this is the most straightforward solution based on the provided information.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Service file should be populated with the DISCORD_BOT_TOKEN env var, or the setup docs/wizard should warn that env vars must be added manually to the service file.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING