Discord Bridge Plugin
Cross-platform bridge connecting Discord and Harmony servers with bi-directional message sync.
Features
- ✅ Bi-directional message sync
- ✅ User mention translation
- ✅ Custom emoji translation (Discord emojis auto-sync to Harmony as federated emojis)
- ✅ Attachment support
- ✅ Reaction syncing
- ✅ Message editing sync
- ✅ Message deletion sync
- ✅ Loop prevention
- ✅ Configurable channel mappings
Prerequisites
- A running Harmony instance with the Bot Gateway
- Node.js 18+
- A Discord bot token
- A Harmony bot token (created via admin panel)
Setup
1. Install Dependencies
bash
cd bot-plugins/discord-bridge
npm install2. Create a Discord Bot
- Go to Discord Developer Portal
- Create a new application
- Go to "Bot" tab and create a bot
- Copy the bot token
- Enable Message Content Intent under Privileged Gateway Intents
- Invite the bot to your server with permissions:
- Read Messages / View Channels
- Send Messages
- Read Message History
3. Create a Harmony Bot
- Log into your Harmony admin panel
- Go to Bot Management
- Create a new bot
- Copy the bot token
- Add the bot to your Harmony server with permissions:
- Read Messages
- Send Messages
4. Configure the Bridge
bash
cp config/bridge-config.example.yml config/bridge-config.ymlEdit config/bridge-config.yml:
yaml
discord:
token: "YOUR_DISCORD_BOT_TOKEN"
guildId: "123456789012345678"
harmony:
token: "YOUR_HARMONY_BOT_TOKEN"
gatewayUrl: "ws://localhost:3002/gateway" # Local dev
apiUrl: "http://localhost:3002/api/v1" # Local dev
channelMappings:
- discord: "987654321098765432"
harmony: "550e8400-e29b-41d4-a716-446655440000"
bidirectional: true
name: "general"
- discord: "111222333444555666"
harmony: "650e8400-e29b-41d4-a716-446655440000"
bidirectional: true
name: "announcements"
settings:
syncAttachments: true
syncReactions: true
syncEdits: true
syncDeletes: true
mentionTranslation: trueTo get channel IDs:
- Discord: Enable Developer Mode in Discord Settings → right-click channel → Copy ID
- Harmony: Check channel URL or use developer tools
5. Start the Bridge
bash
npm run devYou should see:
✅ Connected to Harmony gateway
✅ Harmony bot connected: YourBotName
✅ Discord bot connected: BotTag#1234How It Works
Discord → Harmony
User sends message in Discord
↓
Bridge receives via discord.js
↓
Translate mentions and emojis
↓
Format: **[Discord]** username: message
↓
Send to Harmony via Bot API
↓
Appears in Harmony channelHarmony → Discord
User sends message in Harmony
↓
Bridge receives via WebSocket gateway
↓
Check if from Discord (avoid loop)
↓
Format: **[Harmony]** username: message
↓
Send to Discord channel
↓
Appears in Discord channelLoop Prevention
The bridge prevents infinite loops by:
- Ignoring all bot messages
- Checking for
[Discord]and[Harmony]prefixes - Not bridging messages that are already bridged
Production Deployment
Production URLs
Update your config for production:
yaml
harmony:
token: "YOUR_HARMONY_BOT_TOKEN"
gatewayUrl: "wss://your-domain.com/bot-gateway/gateway"
apiUrl: "https://your-domain.com/bot-gateway/api/v1"Build & Run
bash
npm run build
npm startDocker
dockerfile
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY dist ./dist
COPY config ./config
CMD ["npm", "start"]Docker Compose
yaml
services:
discord-bridge:
build: ./bot-plugins/discord-bridge
environment:
- NODE_ENV=production
volumes:
- ./bot-plugins/discord-bridge/config:/app/config
restart: unless-stoppedPM2
bash
cd bot-plugins/discord-bridge
npm run build
pm2 start dist/index.js --name "harmony-discord-bridge"
pm2 saveTroubleshooting
Messages not bridging
- Check both bots are online
- Verify channel IDs in config are correct
- Check bot permissions in both platforms
- Ensure bot-gateway is running (for Harmony side)
- Check bridge logs for errors
Mentions not translating
- Ensure
mentionTranslation: truein config - Discord mentions require the mentioned user to be in the server
- Harmony mentions use profile ID
Attachments not working
- Set
syncAttachments: truein config - Attachments are linked, not re-uploaded
- Ensure bots have embed/attachment permissions
Bot can't connect to Harmony
- Is the bot-gateway running? (
curl http://localhost:3002/health) - Correct URLs in bridge config? (
ws://localhost:3002/gateway) - Valid bot token? (check admin panel)
- Supabase credentials set in bot-gateway
.env?
Bot can't connect in production
- Nginx config updated and reloaded?
- Bot gateway service running?
- Using
wss://(notws://) in production config? - HTTPS certificate valid?
Limitations
- No voice/video bridging
- Embeds are simplified
- 2000 character Discord limit applies
- Custom Discord emojis are synced to Harmony as federated emojis
Bot Gateway Setup
For complete bot gateway deployment instructions (Nginx, systemd, Docker, environment variables), see the Bot Gateway Setup Guide.
