This script forwards messages from multiple Telegram channels to specified Discord channels.
It uses both a Discord Webhook and a Discord Command Bot in parallel:
- Discord Webhooks forward messages. This retains dynamic branding—the messages appear in Discord with the actual Telegram channel's name and profile photo.
- Discord Bot listens for commands directly inside Discord (like
!add,!remove,!list,!status), allowing you to manage mappings dynamically without restarting or editing config files.
- Python 3.8+ (your current system has Python 3.14.6)
- A Telegram account
- A Discord server where you have permission to manage webhooks and invite bots.
The project files are located in:
C:\Users\Monu\.gemini\antigravity\scratch\telegram-discord-forwarder\
Open your terminal (PowerShell, Command Prompt, or Bash) in the project directory and run:
# Optional but recommended: Create a virtual environment
python -m venv venv
venv\Scripts\activate # On Windows
source venv/bin/activate # On Linux/macOS
# Install required packages
python -m pip install -r requirements.txt- Log in to your Telegram account at my.telegram.org.
- Go to API development tools.
- Create a new application and note your App api_id and App api_hash.
- In your Discord server, right-click a text channel and select Edit Channel.
- Go to Integrations > Webhooks > Create Webhook and copy the Webhook URL.
- Go to the Discord Developer Portal.
- Click New Application, name it, and click Create.
- Go to the Bot tab on the left. Click Reset Token (or Copy Token) and save your Bot Token.
- Scroll down to Privileged Gateway Intents and enable Message Content Intent (click Save Changes).
- Go to OAuth2 tab > URL Generator:
- Select scope:
bot - Select bot permissions:
Send Messages,Embed Links,Attach Files
- Select scope:
- Copy the URL at the bottom, open it in your browser, and invite the bot to your Discord server.
Open config.yaml and update it with your credentials:
telegram:
api_id: 1234567 # Change to your Telegram API ID
api_hash: "your_api_hash" # Change to your Telegram API Hash
phone: "+1234567890" # Change to your phone number
discord:
bot_token: "YOUR_DISCORD_BOT_TOKEN_HERE" # Put your Discord Bot Token here
discord_webhooks:
default: "https://discord.com/api/webhooks/YOUR_WEBHOOK_URL_HERE"Your Discord Bot listens for the following commands in any text channel it has access to:
!status: Displays connection health for Telegram and Discord, and tells you how many channels are active.!list: Lists all active Telegram channels being forwarded and their target webhook paths.!add <telegram_channel_username_or_id> <discord_webhook_url>: Dynamically maps and subscribes to a new Telegram channel.- Example:
!add -1003827118873 https://discord.com/api/webhooks/... - Example:
!add durov https://discord.com/api/webhooks/...
- Example:
!remove <telegram_channel_username_or_id_or_title>: Dynamically unsubscribes and removes a mapping.- Example:
!remove -1003827118873or!remove durov
- Example:
Note: Dynamic mappings added or removed via Discord chat commands are automatically persisted to a local dynamic_mappings.json file.
- Push your repository to GitHub (ensure it is Private).
- Go to share.streamlit.io and deploy your app selecting the
mainbranch and setting the main file path toapp.py. - In your Streamlit App settings, go to the Secrets tab and paste your configuration in TOML format:
# Telegram API Credentials
[telegram]
api_id = 20861184
api_hash = "90455d0cdedfe6bb16bd716e2438703b"
phone = "+917499224791"
# Discord Bot Token (For commands)
[discord]
bot_token = "YOUR_DISCORD_BOT_TOKEN_HERE"
# Discord Webhook Configurations (For forwarding)
[discord_webhooks]
default = "https://discord.com/api/webhooks/YOUR_WEBHOOK_URL_HERE"
# Base mappings
[[mappings]]
telegram_channel = "-1003827118873"
webhook_key = "default"
# General Settings
[settings]
forward_media = true
download_max_size_mb = 25
temp_dir = "./temp"
use_telegram_profile = true- Save the secrets and click Start Bot in your Streamlit dashboard. Authenticate your Telegram session on-screen during the first run.