Channels
Openclaw_discord_plugin
The Openclaw offical discord channel, currently do not respect the env setting as decribe in https://github.com/openclaw/openclaw/issues/27409 . this is a approach to use a plugin to fix the issue
Install
npm install
#
README
# OpenClaw Discord Proxy Plugin
A workaround plugin for OpenClaw's Discord channel that properly respects proxy configuration for both WebSocket and REST API calls.
## Problem
The official OpenClaw Discord channel has a bug (issue [#27409](https://github.com/openclaw/openclaw/issues/27409)) where:
- Gateway WebSocket connections respect the proxy configuration โ
- REST API calls (sending messages) do NOT respect the proxy configuration โ
- Result: Bot can receive messages but cannot send replies, showing "fetch failed" errors
This plugin provides a complete workaround by implementing a Discord channel handler with proper proxy support for both WebSocket and REST API calls.
## Architecture
### How the Plugin Works
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ OpenClaw Gateway โ
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Plugin System โ โ
โ โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ Discord Proxy Plugin (This Plugin) โ โ โ
โ โ โ โ โ โ
โ โ โ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โ โ โ
โ โ โ โ createDiscord โโโโโถโ HttpsProxyAgent โ โ โ โ
โ โ โ โ Client() โ โ Injection โ โ โ โ
โ โ โ โ โ โ โ โ โ โ
โ โ โ โ - Configures โ โ - Wraps HTTP โ โ โ โ
โ โ โ โ Intents โ โ requests โ โ โ โ
โ โ โ โ - Sets up โ โ - Routes all โ โ โ โ
โ โ โ โ Event โ โ traffic โ โ โ โ
โ โ โ โ Handlers โ โ through proxy โ โ โ โ
โ โ โ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โ โ โ
โ โ โ โ โ โ โ โ
โ โ โ โผ โผ โ โ โ
โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ
โ โ โ โ discord.js Client (v14) โ โ โ โ
โ โ โ โ โ โ โ โ
โ โ โ โ โข WebSocket Connection โโโ โ โ โ โ
โ โ โ โ โข REST API Calls โโโโโโโโโผโโโถ Both use proxy agent โ โ โ โ
โ โ โ โ โข Event Processing โ โ โ โ โ
โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โ โ Message Flow โ โ โ
โ โ โ โ โ โ
โ โ โ Inbound: Discord โ Plugin โ Session Key โ OpenClaw Agent โ โ โ
โ โ โ Outbound: OpenClaw Agent โ Plugin โ Discord (via proxy) โ โ โ
โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโ
โ HTTP Proxy โ
โ (e.g., 127.0.0.1:7890)โ
โโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโ
โ Discord API โ
โ โข Gateway (WS) โ
โ โข REST (HTTPS) โ
โโโโโโโโโโโโโโโโโโโโโโโโโ
```
### Key Fix: Proxy Injection Point
The critical fix for issue #27409 is injecting the proxy agent at client creation time:
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Official Channel (Bug) โ Discord Proxy Plugin (Fixed) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ
โ Discord.js Client โ Discord.js Client โ
โ โโโโโโโโโโโโโโโโโโโโโโโโ โ โโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ WebSocket: โ Proxy โ โ โ WebSocket: โ Proxy โ โ
โ โ REST: โ No Proxy โ โ โ REST: โ Proxy โ โ
โ โ (fetch failed) โ โ โ (via HttpsProxyAgent)โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโ โ โโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โฒ โ
โ Config: proxy set โ โ โ
โ Result: Partial working โ Config: proxy set โ
โ โ Result: Full proxy support โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The Fix (src/index.ts: createDiscordClient):
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
if (proxyUrl) {
const proxyAgent = new HttpsProxyAgent(proxyUrl);
clientOptions.rest = {
agent: proxyAgent as any, // โ Injects proxy into REST calls
};
}
```
### Integration with OpenClaw
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ OpenClaw Ecosystem โ
โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ User โโโโโโถโ Discord โโโโโโถโ Discord Proxy Plugin โ โ
โ โ Message โ โ Bot/Gateway โ โ - Message received โ โ
โ โ โโโโโโโ โโโโโโโ - Session key generated โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โ - Forward to OpenClaw โ โ
โ โโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ OpenClaw Gateway โ โ
โ โ - Session routing โ โ
โ โ - Agent workspace โ โ
โ โ - Memory/context โ โ
โ โโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Pi Agent (LLM) โ โ
โ โ - Process message โ โ
โ โ - Generate response โ โ
โ โโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Discord Proxy Plugin โ โ
โ โ - Receive response โ โ
โ โ - Send via proxy โ โ
โ โโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โผ โ
โ โโโโโโโโโโโโโโโโ โ
โ โ Discord โ โ
โ โ (via proxy)โ โ
โ โโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
### Session Key Generation
The plugin generates OpenClaw-compatible session keys for proper message routing:
```typescript
// For DM messages:
{
agentId: 'default',
channel: 'discord',
accountId: 'default',
peer: '<user_id>'
}
// For guild messages:
{
agentId: 'default',
channel: 'discord',
accountId: 'default',
guildId: '<guild_id>',
channelId: '<channel_id>'
}
```
## Features
- โ
**Full proxy support** for both WebSocket and REST API calls
- โ
**Device ID mechanism** for session management and identification
- โ
**Multi-account support** with per-account proxy configuration
- โ
**All official channel features**: DMs, guilds, pairing, allowlists
- โ
**Drop-in replacement** configuration (disable official, enable plugin)
- โ
**Thread bindings** for subagent sessions
- โ
**Interactive components** (buttons, selects, modals)
- โ
**Voice channel support** (with proxy)
- โ
**Exec approvals** via Discord buttons
## Installation
### Prerequisites
- Node.js >= 18.0.0
- OpenClaw >= 2024.1.0
- A Discord bot token (get from [Discord Developer Portal](https://d
... (truncated)
channels
Comments
Sign in to leave a comment