This project is a Discord to Telegram message forwarder. It allows forwarding messages sent by specific users or all users from a Discord channel to a Telegram chat. It is highly configurable and utilizes a MySQL database to manage message forwarding configurations.
- Installation
- Configuration
- Database Setup
- Usage
- Features
- Dependencies
- Slash Commands
- Troubleshooting
To set up this message forwarder, follow these steps:
-
Clone the repository:
git clone https://github.com/johnmalek312/DiscordToTelegram.git cd DiscordToTelegram -
Install the required Python packages:
pip install -r requirements.txt
-
Set up a MySQL database, following the schema provided in the Database Setup section.
-
Set up the configuration by filling out the
.envfile (details below).
Create a .env file in the project root directory with the following environment variables:
DISCORD_TOKEN=your_discord_bot_token
TELEGRAM_TOKEN=your_telegram_bot_token
MYSQL_HOST=your_mysql_host
MYSQL_USER=your_mysql_user
MYSQL_PASSWORD=your_mysql_password
MYSQL_DATABASE=your_database_name
DISCORD_TOKEN: Your Discord bot token.TELEGRAM_TOKEN: Your Telegram bot token.MYSQL_HOST: The hostname of your MySQL server.MYSQL_USER: The username for MySQL access.MYSQL_PASSWORD: The password for the MySQL user.MYSQL_DATABASE: The name of your MySQL database.
You need to set up a MySQL database and create the following table to store the forwarding configuration:
CREATE TABLE forwarder (
id INT NOT NULL PRIMARY KEY,
discord BIGINT NOT NULL,
telegram BIGINT NOT NULL,
header VARCHAR(255) NOT NULL,
whitelist INT DEFAULT NULL
);id: Unique identifier for each forwarding configuration.discord: Discord user/channel ID.telegram: Telegram chat ID.header: A message header to include in forwarded messages.whitelist: Optional user whitelist for restricting forwarding.
-
Start the bot by running the following command:
python main.py
-
The bot will listen to messages in Discord and forward them to the specified Telegram chats based on the configuration stored in the MySQL database.
-
You can customize which users' messages are forwarded by modifying the
whitelistcolumn in theforwardertable.
- Forward messages from Discord to Telegram.
- Optionally forward messages only from specific users.
- Flexible configuration using a MySQL database.
- Automatically reconnects to the database if the connection is lost.
- Manage channel forwarding from Discord to Telegram effortlessly using simple discord bot commands.
Once the bot is running, you need to sync the slash commands in your Discord server. Follow these steps:
-
In your Discord server, with admin permissions, type:
.sync -
This will enable slash commands such as
/add,/list, and others, which will be described in Discord once synced.
These commands allow you to manage the bot more easily, providing more control over what and how messages are forwarded.
- Python 3.8+
- discord.py
- python-telegram-bot
- MySQL Connector
To install dependencies, simply run:
pip install -r requirements.txt- MySQL Connection Issues: Ensure that the MySQL credentials in the
.envfile are correct and that your database server is running. - Discord Bot Not Responding: Make sure the bot has the necessary permissions in the Discord server, and that the
DISCORD_TOKENis valid. - Telegram Messages Not Forwarding: Verify that the Telegram bot has access to the target chat, and the
TELEGRAM_TOKENis correctly set in the.envfile.