Get your dream built 10x faster

How to integrate Discord with OpenClaw

We build custom applications 5x faster and cheaper 🚀

Book a Free Consultation
4.9
Clutch rating 🌟
600+
Happy partners
17+
Countries served
190+
Team members
Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Stuck on an error? Book a 30-minute call with an engineer and get a direct fix + next steps. No pressure, no commitment.

How to integrate Discord with OpenClaw

Direct answer: To integrate Discord with OpenClaw you treat Discord like any external API-driven service: create a Discord application and bot (or OAuth2 app) on Discord, host a public webhook/interaction endpoint outside the agent (so Discord can reach it), verify incoming requests (Ed25519 signature), store bot tokens and OAuth credentials securely in ClawHub as environment secrets, configure an OpenClaw skill that calls Discord’s REST APIs (using the bot token or user OAuth token) for sending messages or performing actions, and keep stateful or long-running pieces (queues, DBs, schedulers) outside the OpenClaw runtime. Authenticate explicitly, respect scopes and intents, and debug by checking logs, API responses, and token scopes.

 

 

Initial checklist — what you need from Discord and from OpenClaw

 
  • Discord side: a Discord application, a bot token (for a bot account) or OAuth2 client credentials (for user OAuth flows), webhook/interaction verification public key, and the proper gateway intents or OAuth scopes for what you need.
  • OpenClaw/ClawHub side: a skill configured to call external REST APIs, secret storage for tokens/keys, a publicly reachable webhook URL (hosted outside the agent), and environment variables for secrets.
  • Runtime: an external web server to receive Discord interactions/webhooks, and optional persistence (DB/queue) outside the agent for any state that must survive restarts.

 

 

Step 1 — Create and configure your Discord application

 
  • Create a Discord application at Discord’s developer portal and add a bot to it.
  • Copy the bot token and the application public key (used to verify incoming interaction signatures). Store both in your ClawHub secret store or as environment variables in your skill configuration.
  • Grant the bot the minimum permissions it needs, and if your bot will receive gateway events (messages, joins), enable the corresponding gateway intents. If you only use HTTP interactions (slash commands, webhooks), you don’t need gateway connections.
  • If you need user-level actions, set up OAuth2 client ID and client secret and plan for the OAuth2 authorization code flow to obtain user tokens with the right scopes (identify, guilds, oauth2.scopes you need).

 

 

Step 2 — Host a public endpoint for Discord interactions

 
  • Discord will call a public HTTPS endpoint for slash commands and some webhooks. This endpoint must be reachable from the public internet (use a cloud VM, serverless function, or tunneling during development like ngrok).
  • Implement request verification using Discord’s Ed25519 signature scheme — verify the X-Signature-Ed25519 and X-Signature-Timestamp headers against the request body using the application public key. Reject requests that fail verification.
  • Respond to interactions quickly (Discord requires an initial acknowledgement within a few seconds). If your processing is slow, send an acknowledgement and then follow up asynchronously.

 

 

Step 3 — Configure the OpenClaw skill (ClawHub)

 
  • In ClawHub, create or configure a skill that will call Discord’s REST APIs. Put sensitive values (bot token, client secret, public key) into the ClawHub secret store or environment variables — never hard-code them into source files.
  • Define the webhook URL (the public endpoint you hosted) as the target for Discord interactions in the Discord developer console.
  • Keep the skill logic that calls Discord stateless where possible; for anything that must persist (users, tokens, queue tasks), use an external DB or storage service and reference it from your skill.

 

 

Step 4 — Authentication approaches

 
  • Bot token (server actions): For posting messages or performing bot actions in servers where your bot is installed, use the bot token in an Authorization header: Authorization: Bot <BOT\_TOKEN>.
  • User OAuth (user-scoped actions): If you need to act on behalf of a user, implement the OAuth2 authorization code flow. Exchange the authorization code for access and refresh tokens, store tokens securely (outside the agent), and refresh when needed.
  • Set and verify scopes carefully — only request the permissions you need (e.g., applications.commands, identify, guilds, messages.read, etc.).

 

 

Step 5 — Verify incoming requests (Ed25519) — example

 

Node.js example using tweetnacl for signature verification:

// <b>//</b> npm install tweetnacl
const nacl = require('tweetnacl');
const { TextEncoder } = require('util');

// <b>//</b> raw request body as Buffer or string, and headers from incoming request
function verifyDiscordRequest(publicKeyHex, signatureHex, timestamp, body) {
  const encoder = new TextEncoder();
  const message = encoder.encode(timestamp + body);
  const publicKey = Buffer.from(publicKeyHex, 'hex');
  const signature = Buffer.from(signatureHex, 'hex');
  return nacl.sign.detached.verify(new Uint8Array(message), new Uint8Array(signature), new Uint8Array(publicKey));
}

// <b>//</b> Usage inside your HTTP handler:
// <b>//</b> const verified = verifyDiscordRequest(PUBLIC_KEY_HEX, req.headers['x-signature-ed25519'], req.headers['x-signature-timestamp'], rawBody);

Python example using pynacl:

# <b>//</b> pip install pynacl
from nacl.signing import VerifyKey
from nacl.exceptions import BadSignatureError

def verify_discord_request(public_key_hex, signature_hex, timestamp, body):
    verify_key = VerifyKey(bytes.fromhex(public_key_hex))
    message = (timestamp + body).encode('utf-8')
    try:
        verify_key.verify(message, bytes.fromhex(signature_hex))
        return True
    except BadSignatureError:
        return False

# <b>//</b> Usage:
# <b>//</b> verified = verify_discord_request(PUBLIC_KEY_HEX, signature_hex, req.headers['x-signature-ed25519'], req_text_body)

 

 

Step 6 — Sending messages and calling Discord APIs

 
  • Use Discord’s REST endpoints to post messages, edit messages, create embeds, or reply to interactions. Authenticate with the Bot token: Authorization: Bot <token>.
  • Basic REST example with curl to post a message to a channel:
# <b>//</b> Replace CHANNEL_ID and BOT_TOKEN
curl -X POST "https://discord.com/api/v10/channels/CHANNEL_ID/messages" \
  -H "Authorization: Bot BOT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"content":"Hello from OpenClaw skill"}'
  • When responding to interactions, you must call the interactions response endpoint quickly. If you can't finish processing within the initial window, send a defer/acknowledgement and then call follow-up message endpoints.

 

 

Step 7 — Runtime architecture: what runs in the agent vs outside

 
  • Agent (skill) responsibilities: short-lived API calls to Discord, translating OpenClaw inputs to Discord REST calls, minimal ephemeral computation, orchestration logic that needs to run when invoked.
  • External services (must be outside the agent): any publicly reachable webhook/interaction endpoint (Discord must reach it), databases for durable storage (tokens, user state), schedulers for periodic tasks, message queues for background work, and any long-lived gateway connections (if you opt to use the Discord Gateway instead of HTTP interactions).
  • Keep the skill idempotent and stateless where possible so it can be retried safely by OpenClaw.

 

 

Step 8 — Security and operational notes

 
  • Never embed the bot token or client secret in source code — keep them in ClawHub secrets or environment variables.
  • Verify all incoming requests using the official verification method (Ed25519). Reject unauthenticated requests early.
  • Respect Discord rate limits: inspect the X-RateLimit-\* headers and back off on 429 responses. Implement exponential backoff for retries.
  • Use least privilege: request minimal scopes/intents and limit bot permissions in guilds.

 

 

Step 9 — Debugging checklist

 
  • Check OpenClaw skill logs and the external webhook server logs for incoming requests and errors.
  • Confirm request verification: are the signature and timestamp headers present and validated?
  • Verify tokens by calling a safe endpoint such as GET /users/@me with the Bot token to confirm it is valid.
  • Ensure OAuth tokens have the right scopes and are not expired; check refresh logic.
  • Inspect Discord API HTTP responses for status codes, error bodies, and rate-limit headers.
  • If interactions time out, verify your endpoint is reachable and that the handler responds within Discord’s interaction window (acknowledge quickly if processing is longer).

 

 

Minimal example flow (summary)

 
  • Create Discord app & bot, store secrets in ClawHub.
  • Host a public HTTPS endpoint to receive interactions; verify signatures.
  • Implement an OpenClaw skill that calls Discord REST APIs using the bot token or user OAuth tokens.
  • Keep long-running state or webhook hosting outside the agent; use external DB/queues as needed.
  • Monitor logs, verify tokens/scopes, and handle rate limits and signature validation.

Book Your Free 30‑Minute Migration Call

Speak one‑on‑one with a senior engineer about your no‑code app, migration goals, and budget. In just half an hour you’ll leave with clear, actionable next steps—no strings attached.

Book a Free Consultation

Troubleshooting Discord and OpenClaw Integration

1

How to configure OpenClaw Discord connector webhook endpoint?

Create a publicly reachable HTTPS endpoint that receives Discord events, verify Discord's Ed25519 signatures on each request, register that URL in the Discord Developer Portal (Interactions/Webhooks), store the Discord public key as an environment variable, and configure your OpenClaw skill in ClawHub to accept and route those events to the agent runtime. Use a proxy (ngrok) for local testing and inspect logs to confirm delivery and skill activation.

 

Configure webhook endpoint

 

Key steps:

  • Expose HTTPS endpoint (runtime or external service).
  • Verify headers: X-Signature-Ed25519, X-Signature-Timestamp.
  • Store Discord public key in env var and configure ClawHub skill routing.
  • Test with ngrok and check logs.
// Express example: verify Discord Ed25519 signature
const nacl = require('tweetnacl');
app.post('/discord-webhook', express.raw({type:'application/json'}), (req, res)=>{
  const signature = req.get('X-Signature-Ed25519');
  const timestamp = req.get('X-Signature-Timestamp');
  const body = req.body; // Buffer
  const msg = Buffer.concat([Buffer.from(timestamp), body]);
  const isValid = nacl.sign.detached.verify(msg, Buffer.from(signature,'hex'), Buffer.from(process.env.DISCORD_PUBLIC_KEY,'hex'));
  if(!isValid) return res.status(401).end();
  // dispatch to OpenClaw skill handler
  res.status(200).end();
});

2

Why are Discord messages not reaching OpenClaw EventBus when using the OpenClaw Discord bridge?

 

Direct answer

 

The bridge most often fails because of misconfiguration: incorrect EventBus URL or auth token, webhook signature validation mismatch, missing Discord permissions/intents (so messages aren’t delivered), or network/TLS/firewall blocking. Check bridge and EventBus logs and Discord delivery diagnostics to locate the failing step.

 

What to check

 
  • EventBus config: URL, API key/token, environment variables.
  • Discord: bot/webhook scopes and required intents (message content if needed).
  • Signature: secret used to validate incoming Discord payloads.
  • Network: DNS, TLS certs, firewall/NAT rules between Discord and bridge/EventBus.
  • Logs & delivery: bridge logs, EventBus auth failures, Discord delivery/webhook diagnostics.
  • Payload mapping: malformed fields or rate limits causing silent drops.

3

How to map Discord guild roles to OpenClaw permission groups using the OpenClaw Auth Adapter?

 

Direct answer

 

Use the OpenClaw Auth Adapter to translate Discord guild role IDs into OpenClaw permission groups during authentication: validate the user’s Discord identity, call the Discord API to read the user’s guild role IDs, consult a maintained mapping (env, config file, or DB) from role ID → group name, then emit those group names as the adapter’s permission claims so OpenClaw skills enforce them.

 

How to implement

 
  • Validate identity: use OAuth2 or bot token to confirm the user and fetch guild member roles via Discord REST API.
  • Maintain mapping: store roleID→groupName in environment variables, a config file, or a small DB for easy updates.
  • Adapter translation: in the Auth Adapter’s mapping step, convert Discord role IDs into OpenClaw groups and attach as claims on the authenticated subject.
  • Permissions: ensure skills check group membership via OpenClaw permission checks; keep least privilege.

4

How to fix OAuth2 token refresh errors between Discord and OpenClaw OAuth Adapter (invalid_grant or 401)?

A common cause of Discord↔OpenClaw OAuth2 refresh errors (invalid_grant or 401) is a mismatch between what your adapter sends and Discord's token rules: wrong client_id/secret, wrong redirect_uri, refresh token rotation (token already used), revoked tokens, or clock skew. Fix by verifying credentials, using the correct token endpoint, sending form-encoded body or Basic auth, and logging full responses.

 

Troubleshooting steps

 
  • Verify client_id/secret, redirect_uri and scopes match the original auth.
  • Check if your adapter reuses a rotated refresh token — store the latest token from token response.
  • Inspect Discord response body and HTTP status in OpenClaw logs for error_description.
  • Ensure system clock is correct.
// <b>//</b> realistic Node.js refresh example using axios
const res = await axios.post('https://discord.com/api/oauth2/token',
  new URLSearchParams({grant_type:'refresh_token', refresh_token, client_id, client_secret}),
  {headers:{'Content-Type':'application/x-www-form-urlencoded'}})
Book a Free Consultation

Still stuck?
Copy this prompt into ChatGPT and get a clear, personalized explanation.

This prompt helps an AI assistant understand your setup and guide you through the fix step by step, without assuming technical knowledge.

AI AI Prompt


Recognized by the best

Trusted by 600+ businesses globally

From startups to enterprises and everything in between, see for yourself our incredible impact.

RapidDev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with.

They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

Arkady
CPO, Praction
Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost.

He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Donald Muir
Co-Founder, Arc
RapidDev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space.

They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Mat Westergreen-Thorne
Co-CEO, Grantify
RapidDev is an excellent developer for custom-code solutions.

We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Emmanuel Brown
Co-Founder, Church Real Estate Marketplace
Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 

This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Samantha Fekete
Production Manager, Media Production Company
The pSEO strategy executed by RapidDev is clearly driving meaningful results.

Working with RapidDev has delivered measurable, year-over-year growth. Comparing the same period, clicks increased by 129%, impressions grew by 196%, and average position improved by 14.6%. Most importantly, qualified contact form submissions rose 350%, excluding spam.

Appreciation as well to Matt Graham for championing the collaboration!

Michael W. Hammond
Principal Owner, OCD Tech

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We’ll discuss your project and provide a custom quote at no cost.Â