3 releases
Uses new Rust 2024
| 0.1.3 | Feb 28, 2026 |
|---|---|
| 0.1.1 | Feb 28, 2026 |
| 0.1.0 | Feb 25, 2026 |
#423 in Network programming
520KB
14K
SLoC
matrix-bridge-discord
A Matrix <-> Discord bridge written in Rust.
Maintainer: Palpo Team
Contact: chris@acroidea.com
Overview
- Rust-only implementation (legacy Node.js/TypeScript code has been removed)
- Matrix appservice + Discord bot bridge core
- HTTP endpoints for health/status/metrics and provisioning
- Database backends: PostgreSQL, SQLite, and MySQL (feature-gated)
- Dockerfile for local build and container runtime
Repository Layout
src/: bridge implementationconfig/config.sample.yaml: sample configurationmigrations/: database migrationsDockerfile: multi-stage container build
Prerequisites
- Rust toolchain (compatible with the project; Docker build uses Rust 1.93)
- A Matrix homeserver configured for appservices
- A Discord bot token
- Database: PostgreSQL, SQLite, or MySQL
Quick Start (Local)
- Create your config file:
cp config/config.sample.yaml config.yaml
-
Set the required values in
config.yaml:bridge.domainauth.bot_tokendatabase.url(ordatabase.conn_string/database.filename)- registration values via either:
registration.id,registration.as_token,registration.hs_token, ordiscord-registration.yamlnext to your config file, or- env vars (see Environment Overrides below)
-
Run:
cargo check -p matrix-bridge-discord
cargo test -p matrix-bridge-discord --no-run
cargo run -p matrix-bridge-discord
- Verify:
curl http://127.0.0.1:9005/health
curl http://127.0.0.1:9005/status
Configure Discord (Step by Step)
- Go to https://discord.com/developers/applications and create a new application.
- Open the Bot tab, create a bot user, then copy:
- Application ID (for
auth.client_id) - Bot token (for
auth.bot_token)
- Application ID (for
- If you want privileged intents, enable them in the Discord portal and set
auth.use_privileged_intents: true. - Invite the bot to your guild(s). Recommended permissions:
- View Channels
- Send Messages
- Embed Links
- Attach Files
- Read Message History
- Manage Webhooks
- Fill the auth section in
config.yaml:
auth:
client_id: "123456789012345678"
bot_token: "YOUR_DISCORD_BOT_TOKEN"
client_secret: null
use_privileged_intents: false
- To bridge a specific Discord channel, collect IDs from:
https://discord.com/channels/<guild_id>/<channel_id>
Configure Matrix / Palpo (Step by Step)
- In Palpo config (
palpo.toml), set your server name and appservice registration directory:
server_name = "example.com"
appservice_registration_dir = "appservices"
- Place your bridge registration file under that directory, for example:
appservices/discord-registration.yaml
- Ensure tokens are consistent between Palpo registration and bridge config:
as_tokenin registration == bridge appservice tokenhs_tokenin registration == bridge homeserver token
- Ensure bridge homeserver fields point to Palpo:
bridge:
domain: "example.com"
homeserver_url: "http://127.0.0.1:6006" # Replace with your Palpo URL
- Start Palpo, then start this bridge.
- Confirm connectivity both ways:
- Palpo must reach bridge registration
url(for appservice transactions) - Bridge must reach
bridge.homeserver_url(your Palpo endpoint)
- Palpo must reach bridge registration
Notes:
- If Palpo and bridge run in different containers/hosts, do not use loopback addresses unless they are in the same network namespace.
- For Docker Desktop,
host.docker.internalis often useful when bridge container needs to reach host Palpo.
Configure Matrix / Synapse (Step by Step)
- Set your Matrix-facing values in
config.yaml:
bridge:
domain: "example.com"
homeserver_url: "https://matrix.example.com"
bind_address: "0.0.0.0"
port: 9005
- Create
discord-registration.yamlnext toconfig.yaml(or setREGISTRATION_PATH):
id: "discord"
url: "http://127.0.0.1:9005"
as_token: "CHANGE_ME_AS_TOKEN"
hs_token: "CHANGE_ME_HS_TOKEN"
sender_localpart: "_discord_"
rate_limited: false
protocols: ["discord"]
namespaces:
users:
- exclusive: true
regex: "@_discord_.*:example.com"
aliases:
- exclusive: true
regex: "#_discord_.*:example.com"
rooms: []
- In Synapse
homeserver.yaml, add:
app_service_config_files:
- /path/to/discord-registration.yaml
- Ensure the registration
urlis reachable by Synapse.- Same host:
http://127.0.0.1:9005is fine. - Different host/container: use a routable address.
- Same host:
- Restart Synapse, then start this bridge.
Notes:
bridge.domainshould match your Matrix server domain (right side of MXIDs).bridge.homeserver_urlshould be the real homeserver URL (preferably public HTTPS if Discord needs to fetch media).- If
registrationfields are missing inconfig.yaml, values are loaded fromdiscord-registration.yaml.
Docker
Build:
docker build -t ghcr.io/palpo-im/matrix-bridge-discord:main -f Dockerfile .
Run (expects /data/config.yaml in the mounted directory):
docker run --rm \
-p 9005:9005 \
-v "$(pwd)/config:/data" \
-e CONFIG_PATH=/data/config.yaml \
ghcr.io/palpo-im/matrix-bridge-discord:main
Notes:
- Container listens on
0.0.0.0:9005by default. - Health check endpoint:
GET /health - Default registration file path is
discord-registration.yamlresolved relative toCONFIG_PATH.
Database Configuration
The bridge auto-detects DB type from connection string prefix:
postgres://orpostgresql://-> PostgreSQLsqlite://-> SQLitemysql://ormariadb://-> MySQL / MariaDB- anything else -> PostgreSQL fallback
MySQL backend note:
- Build with the
mysqlfeature enabled, e.g.cargo run -p matrix-bridge-discord --features mysql - Install
libmysqlclient(or MariaDB Connector/C) somysqlclient-syscan link
Examples:
database:
url: "postgresql://user:password@localhost:5432/matrix_bridge"
max_connections: 10
min_connections: 1
database:
url: "sqlite://./data/matrix-bridge.db"
database:
url: "mysql://user:password@localhost:3306/matrix_bridge"
max_connections: 10
min_connections: 1
Environment Overrides
The following environment variables are supported:
CONFIG_PATHREGISTRATION_PATHAPPSERVICE_DISCORD_AUTH_BOT_TOKENAPPSERVICE_DISCORD_AUTH_CLIENT_IDAPPSERVICE_DISCORD_AUTH_CLIENT_SECRETAPPSERVICE_DISCORD_REGISTRATION_IDAPPSERVICE_DISCORD_REGISTRATION_AS_TOKENAPPSERVICE_DISCORD_REGISTRATION_HS_TOKENAPPSERVICE_DISCORD_REGISTRATION_SENDER_LOCALPART
Dependencies
~151MB
~3.5M SLoC