Skip to content

Repository files navigation

discord-alert-bridge

Language: English | 简体中文

Forward messages from selected Discord channels to Lark / Feishu, Gmail, or DingTalk.

The project includes a local web console for editing configuration, starting or stopping the bridge, sending a test notification, viewing logs, and reviewing recently captured messages.

Features

  • Monitor one or more Discord channel URLs or channel IDs.
  • Parse channel, author, message content, attachments, and embeds.
  • Forward to Lark / Feishu with an interactive card layout.
  • Forward to Gmail through SMTP.
  • Forward to DingTalk through a custom robot webhook.
  • Local admin console at http://127.0.0.1:8765.
  • Optional admin login for the local console.
  • Test notification button for validating Lark / Gmail / DingTalk without starting Discord monitoring.
  • Runtime log, per-session log view, clear-log action, and recent-message storage.

Screenshots

Admin Console

Admin console preview

Recent Messages

Recent message history preview

Lark / Feishu Notification

Lark notification card preview

Important Notice

This project currently reads Discord credentials from DISCORD_USER_TOKEN. Automating a personal Discord account may violate Discord's terms and can put the account at risk. Use only in environments where you have authorization and understand the risk. Do not commit tokens, webhook URLs, email passwords, logs, or message history.

Get a Discord User Token

The steps below use Chrome / Edge DevTools to read the token from network requests. Firefox and Safari follow the same idea.

1. Sign in to Discord in the browser

  1. Open https://discord.com/app
  2. Sign in with the account you want to monitor

2. Open DevTools

  1. Press F12, or right-click the page and choose Inspect
  2. Open the Network tab
  3. Enable Preserve log so requests are not cleared when you navigate
  4. Filter by api to show Discord API calls only

3. Trigger an API request

Any of these works:

  • Refresh the page (Cmd+R / Ctrl+R)
  • Click a server or channel in the sidebar
  • Send a test message in any channel

You should see requests to discord.com/api/... appear in the list.

4. Copy the authorization header

  1. Click any discord.com/api request
  2. Open HeadersRequest Headers
  3. Find the authorization field
  4. Copy the full value into .env as DISCORD_USER_TOKEN, or paste it into the User Token field in the web console

Example:

DISCORD_USER_TOKEN=your_long_token_string

If the copied value includes a Bearer prefix, that is fine. This project strips it automatically.

5. Verify the token

Valid Invalid
A long alphanumeric string from the authorization header Starts with Bot (that is a bot token)
Stored only in your local .env A full browser cookie string (__dcfduid=...)
Used for your own local testing Shared in chat, screenshots, or committed to Git

After saving, use Test notification or Start monitoring in the web console. If the token is invalid, the log will show an auth failure. Sign out and back in to Discord, then extract a fresh token.

Security notes

  • A user token is effectively your Discord login credential. Anyone with it can act as your account.
  • Close DevTools after extraction and never share the token.
  • If a token may have leaked, change your Discord password immediately to invalidate it, then extract a new one.

Quick Start

1. Install

git clone https://github.com/TokenScience01/discord-alert-bridge.git
cd discord-alert-bridge

python3 -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\activate

pip install -r requirements.txt
cp .env.example .env

If you use Conda:

git clone https://github.com/TokenScience01/discord-alert-bridge.git
cd discord-alert-bridge

conda activate discord-alert-bridge   # or create first: conda create -n discord-alert-bridge python=3.11 -y
pip install -r requirements.txt
cp .env.example .env

2. Configure

Edit .env, or use the web console.

Minimum fields:

ADMIN_USERNAME=admin
ADMIN_PASSWORD=change_this_password

DISCORD_USER_TOKEN=replace_with_authorized_token
DISCORD_CHANNEL_URLS=https://discord.com/channels/YOUR_GUILD_ID/YOUR_CHANNEL_ID

LARK_ENABLED=true
LARK_WEBHOOK_URL=https://open.larksuite.com/open-apis/bot/v2/hook/replace_me

Gmail and DingTalk can be enabled at the same time. See .env.example for all variables.

3. Start The Admin Console

cd discord-alert-bridge
source .venv/bin/activate   # if using venv
python3 admin.py

Or with Conda:

cd discord-alert-bridge
conda activate discord-alert-bridge
python admin.py

Open:

http://127.0.0.1:8765

On macOS, you can also double-click:

start_admin.command

4. Start Monitoring

In the web console, save the configuration and click Start Listening.

You can also run the bridge directly:

python3 main.py

Or install the package in editable mode:

pip install -e .
discord-alert-bridge
discord-alert-bridge-admin

Web Console

The local console supports:

  • Login and logout.
  • Saving .env configuration.
  • Auto-filling guild ID and channel ID from Discord channel URLs.
  • Starting, stopping, and toggling the bridge process.
  • Sending a test notification without Discord monitoring.
  • Viewing the current session log.
  • Clearing the log.
  • Viewing recently recorded messages grouped by channel.

Default console credentials come from .env.example:

ADMIN_USERNAME=admin
ADMIN_PASSWORD=changeme

Change ADMIN_PASSWORD before keeping the console running.

Configuration

Admin

Variable Description
ADMIN_USERNAME Local web console username.
ADMIN_PASSWORD Local web console password.

Discord

Variable Description
DISCORD_USER_TOKEN Authorized Discord user token used by the gateway client. Keep it private.
DISCORD_CHANNEL_URLS One or more Discord channel URLs, comma-separated.
DISCORD_CHANNEL_IDS Optional explicit channel IDs.
DISCORD_ALLOWED_GUILD_IDS Optional guild allow-list.
DISCORD_GATEWAY_PROXY Empty = library/system default; none = direct connection; or an explicit proxy such as socks5://127.0.0.1:7890.
ALERT_PREFIX Prefix used in forwarded notifications.
LOG_LEVEL DEBUG, INFO, WARNING, or ERROR.

Channel URL format:

https://discord.com/channels/GUILD_ID/CHANNEL_ID

Lark / Feishu

Variable Description
LARK_ENABLED Set to true to enable Lark forwarding.
LARK_WEBHOOK_URL Custom bot webhook URL.
LARK_SECRET Optional signing secret.

Gmail

Variable Description
GMAIL_ENABLED Set to true to enable Gmail forwarding.
SMTP_HOST SMTP server, defaults to smtp.gmail.com.
SMTP_PORT SMTP port, defaults to 587.
SMTP_STARTTLS Set to true for STARTTLS.
SMTP_USERNAME SMTP username.
SMTP_PASSWORD SMTP password or Gmail App Password.
SMTP_FROM Sender address.
SMTP_TO Recipient addresses, comma-separated.

For Gmail, an App Password is usually required when two-step verification is enabled.

DingTalk

Variable Description
DINGTALK_ENABLED Set to true to enable DingTalk forwarding.
DINGTALK_WEBHOOK_URL Custom robot webhook URL.
DINGTALK_SECRET Optional signing secret.

Runtime Files

The app may create these local files:

File Purpose
.env Local secrets and configuration.
admin.log Admin console log.
bridge.log Bridge runtime log.
.bridge.pid Running bridge process ID.
.admin.pid Admin process ID when started manually.
messages.json Recently recorded forwarded messages.

These files are ignored by Git because they may contain tokens, webhook URLs, or message content.

Development

pip install -e ".[test]"
python3 -m unittest discover -s tests -v

Project Structure

discord-alert-bridge/
├── discord_alert_bridge/
│   ├── admin.py            # Admin API and process control
│   ├── admin_auth.py       # Local console authentication
│   ├── admin_ui.py         # Web console HTML/CSS/JS
│   ├── config.py           # Environment configuration
│   ├── discord_gateway.py  # Discord Gateway listener
│   ├── formatting.py       # Notification formatting
│   ├── forwarders.py       # Lark / Gmail / DingTalk forwarding
│   ├── message_store.py    # Recent-message storage
│   ├── models.py           # Shared data models
│   └── paths.py            # Project paths
├── admin.py                # Admin console entrypoint
├── main.py                 # Bridge entrypoint
├── .env.example            # Configuration template
├── requirements.txt
└── tests/

Security Checklist

Before sharing or publishing this repository:

git status
git check-ignore -v .env bridge.log messages.json

Make sure you did not commit:

  • .env
  • Any token or webhook URL
  • Gmail passwords or App Passwords
  • bridge.log, admin.log, or archived logs
  • messages.json
  • Real guild, channel, or message history data

Rotate any token, webhook, or password that may have been exposed.

Discord User Token Risk

This project currently uses a Discord user token + Gateway approach for local testing, without requiring a bot invitation.

Warning: Automating a normal user account may violate the Discord Terms of Service and can lead to account action. Use it only for personal local testing and at your own risk.

If a token or webhook may have leaked, rotate it immediately.

License

MIT License. See LICENSE.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages