📖 繁體中文版README.md 📖 | 📝 What's new (Changelog)
This bot backs up every message sent in a LINE group to a Discord channel in real-time, using a LINE Messaging API bot, a Discord bot and Discord webhooks. Each message is re-posted in Discord under the sender's LINE name and avatar, so the Discord channel reads just like the original chat.
This project is the successor of Discord-Line-Message-Sync, which was archived after LINE Notify shut down. Syncing from Discord back to LINE has been dropped because it uses up the LINE bot's monthly message quota, so this bot is a one-way backup (LINE → Discord).
Supported message types:
| LINE -----backup to----> Discord | Support |
|---|---|
| Text Message | ☑️ |
| Pictures | ☑️ |
| Videos | ☑️ |
| Audios | ☑️ |
| Files | ☑️ |
| Stickers (animated ones become GIFs) | ☑️ |
| Location (with a Google Maps link) | ☑️ |
| LINE emoji (sent as images) | ☑️ |
| Any other types of messages | ❌️ |
Discord can't show LINE emojis inside text, so the text keeps LINE's placeholders like (hello) and the emoji images
are attached to the message. A message with only LINE emojis is sent as images, just like a sticker.
Pictures, videos, audios, files, stickers and LINE emojis are also saved locally in the downloads folder.
To keep the folder from growing forever, you can set downloads_mode in config.yml to limit its size
(size_limit) or remove files right after they are backed up and only keep a sticker and emoji cache (instant_burn), see here.
You can definitely host this service yourself! and it's free! Find it out by the following tutorial!
- A public HTTPS URL that forwards to this bot, so LINE can send webhooks to it, see here if you don't have one
- Only when running from source: Python 3.13, and
uv (recommended) - if uv isn't installed, the run script
falls back to
venv+pip install -r requirements.txt
- Get the bot, either way works:
- Windows (easiest): Download
LineBackupToDiscord-<version>.zipfrom the latest release and unzip it. No need to install Python - From source (Windows / Linux / macOS): Clone this repository, then run
run.bat(Windows) orrun.sh(Linux / macOS) once. It sets up the Python environment, generatesconfig.yml, then exits
- Windows (easiest): Download
- Open up
config.ymland fill in the required information, see here for more details - Start the bot with
LineBackupToDiscord.exe, orrun.bat/run.shif you're running from source - Set up the LINE webhook to point to your server, see here
- Invite the Discord bot to your Discord server, and add the LINE bot to your LINE group
- In the LINE group, tag the bot (
@<your LINE bot name>), then tap邀請好了(invited) in the reply. The bot will send you a 6-digit binding code, with the command in its own message so it's easy to copy. The code can only be used once and expires in 5 minutes. Asking again before it expires gives you the same code - Send
/link <binding_code>in the Discord channel you want to back up to - Done! Every new message in the LINE group will now be backed up to that Discord channel!
| Where | Command | Description |
|---|---|---|
| LINE | @<bot name> |
Tag the bot to start the binding process and get a binding code |
| LINE | !ID |
Show the ID of the current LINE group |
| Discord | /link <binding_code> |
Bind this channel with a LINE group and start backing up messages |
| Discord | /unlink |
Unbind this channel from the LINE group and stop backing up |
| Discord | /about |
Show the bot's information and the LINE group bound with this channel |
| Discord | /help |
Show how to use the bot |
# ++--------------------------------++
# | LineBackupToDiscord (MIT LICENSE)|
# | Made by LD v0.1.1 |
# ++--------------------------------++
# Line Channel Access Token & Secret
# You can get it from https://developers.line.biz/console/
line_channel_access_token: ''
line_channel_secret: ''
# Discord Bot token
# You can get it from https://discord.com/developers/applications
discord_bot_token: ''
# Backend server configuration, aka the webhook server port for LINE.
# If you change port, make sure to change the port in your reverse proxy(ngrok etc..) as well.
webhook_port: 5000
# Downloads folder settings.
# Pictures, videos, audios, files, stickers and emojis are saved in the downloads folder,
# pick how to manage it:
# 'unlimited' - Keep every file forever (default)
# 'size_limit' - Keep the folder under downloads_max_size_mb, the least recently used files
# are removed automatically when it gets bigger than that
# 'instant_burn' - Remove pictures, videos, audios and files right after they are sent to Discord.
# Stickers and emojis are kept as a cache, limited by downloads_max_size_mb
downloads_mode: 'unlimited'
# Max size of the downloads folder in MB, used when downloads_mode is 'size_limit' or 'instant_burn'
downloads_max_size_mb: 1024
# (Optional settings)
# You can fill in your own bot invite link and hosted by information
# This will be shown when someone types /about
# Noted that if you share your bot invite link, anyone can invite your bot to their server
bot_hosted_by: 'PlayfunI Network'
line_bot_invite_link: ''
discord_bot_invite_link: ''Pictures, videos, audios, files and stickers can take up a lot of disk space over time. Use downloads_mode in
config.yml to choose how the downloads folder is managed:
downloads_mode |
What it does |
|---|---|
unlimited (default) |
Keep every file forever |
size_limit |
Keep the folder under downloads_max_size_mb MB. When it gets bigger, the least recently used files are removed first. A sticker package is removed as a whole. The limit is also checked when the bot starts |
instant_burn |
Remove pictures, videos, audios and files right after they're sent to Discord. Sticker packages and LINE emojis are reused every time they're sent, so they're kept as a cache and limited by downloads_max_size_mb the same way as size_limit |
- Go to LINE Developers and login with your LINE account
- If you don't have a Business ID, simply create one by following the instructions
- Then click
Create a new provider - Fill in the required information and click
Create - Click
Create a new channeland selectMessaging API - Fill in the required information and click
Create - You can now find your channel secret in
Basic settingsand channel access token inMessaging API, clickIssueto copy it
Notes: Please make sure you've checked Allow bot to join group chats option and un-checked
Auto-reply messages in your LINE bot settings, which can be found in Messaging API >
LINE Official Account features section.
- Go to LINE Developers and login with your LINE account
- Select your channel application
- Select
Messaging API, findWebhook URLand clickEdit - Fill in your public HTTPS URL and add
/callbackat the end, e.g.https://your-domain.ngrok-free.app/callback - Click
Save, then clickVerifyto make sure the bot is reachable (the bot must be running) - Remember to check
Use webhookunder theWebhook URLsection
Notes: LINE webhook only works with HTTPS, and the bot listens on webhook_port (default 5000), so you need a reverse
proxy that forwards an HTTPS URL to that port. If you don't know how to create one, you can use
ngrok, find out how here.
- Go to Discord Developer Portal and login with your Discord account
- Click
New Application - Fill in the name of application and click
Create - Click
Boton the left side - Click
Reset Tokento get your bot token and copy it - To invite the bot, go to
OAuth2>URL Generator, select thebotandapplications.commandsscopes, and give it theManage Webhookspermission (the bot creates a webhook in the channel when you run/link). Open the generated URL to invite the bot to your server, you can also paste this URL intodiscord_bot_invite_linkinconfig.yml
- Go to Ngrok sign up for an account and login
- Go to the Domains Dashboard, you'll find a free static domain there (or
create one), it should look like
something-random-idontknow.ngrok-free.app - Download and install ngrok from here
- Add your auth token, which can be found here
ngrok config add-authtoken <your_auth_token>
- Start the tunnel, replace
<domain_name>with your domain, and5000with yourwebhook_portif you changed itngrok http --url=<domain_name> 5000
- Done! Now your webhook URL is
https://<domain_name>/callback
- Fork this repository
- Clone your forked repository
- Install uv and run
uv syncto set up the environment - Create a new branch
- Make your changes, run the bot with
uv run main.py - Commit and push your changes
- Create a pull request
- Wait for review
Dependencies are managed with uv (pyproject.toml / uv.lock), and kept up to date by Renovate.
requirements.txt is generated from uv.lock by uv export --no-hashes --frozen > requirements.txt, so please don't
edit it by hand.
Want to build a standalone executable? See build_executable. Release zips are built on Windows by GitHub Actions, see here.
- FastAPI + Uvicorn for webhook server
- LINE Messaging API SDK for LINE bot
- discord.py for Discord bot and webhooks
- Pydantic for data validation
- PyYAML for reading config file
- requests for sending HTTP requests
- Pillow for converting animated stickers to GIFs
- PyInstaller for building executables
- 100 characters per line
- Use
snake_casefor variables and functions - Add a blank line at the end of the file
- Optimize imports, remove the redundant ones
- Google style TODO comments
- Use Sphinx Docstring style for docstrings
- Use Conventional Commits for commit messages, for example
- feat: your commit messages here
- fix: your commit messages here
- refactor: your commit messages here
- build: your commit messages here
- docs: your commit messages here
If you have any suggestions or found any bugs, please open an issue here, will try to fix it as soon as possible.
This project is licensed under the MIT License - see the LICENSE file for details
📖 English README.md 📖 | 📝 更新內容 (Changelog)
這個機器人會將 LINE 群組中的所有訊息即時備份到 Discord 頻道,運用了 LINE Messaging API 機器人、Discord bot 及 Discord webhook 等技術。每則訊息都會以發送者的 LINE 名稱及大頭貼重新發送到 Discord,讓 Discord 頻道看起來就像原本的聊天室一樣。
本專案為 Discord-Line-Message-Sync 的後繼專案, 舊專案已因 LINE Notify 停止服務而封存。由於從 Discord 同步回 LINE 會消耗 LINE 機器人每月的訊息額度,因此已取消該功能, 本機器人為 單向備份 (LINE → Discord)。
目前支援備份的訊息種類:
| LINE -----備份至----> Discord | 支援 |
|---|---|
| 文字訊息 | ☑️ |
| 圖片 | ☑️ |
| 影片 | ☑️ |
| 音檔 | ☑️ |
| 檔案 | ☑️ |
| 貼圖 (動態貼圖會轉為 GIF) | ☑️ |
| 位置訊息 (附 Google 地圖連結) | ☑️ |
| LINE 表情貼 (以圖片傳送) | ☑️ |
| 任何其他種類的訊息 | ❌️ |
由於 Discord 無法在文字中顯示 LINE 表情貼,文字會保留 LINE 的替代文字 (例如 (hello)),並將表情貼圖片附加在訊息中。
只有 LINE 表情貼的訊息則會像貼圖一樣,直接以圖片傳送。
圖片、影片、音檔、檔案、貼圖及 LINE 表情貼也會另外儲存一份在本機的 downloads 資料夾中。
為了避免資料夾無限制地變大,你可以在 config.yml 中設定 downloads_mode 來限制資料夾大小 (size_limit),
或是在備份完成後立即刪除檔案、只保留貼圖及表情貼快取 (instant_burn),請參考 這裡。
想要自己架設這個訊息備份機器人嗎? 快點看看下面的使用教學吧!
- 一個可以轉發到此機器人的 HTTPS 公開網址,讓 LINE 能夠傳送 Webhook,若你沒有的話請參考 這裡
- 僅從原始碼執行時需要:Python 3.13,以及
uv (建議安裝) - 若未安裝 uv,執行腳本會改用
venv+pip install -r requirements.txt來建立環境
- 取得機器人,以下兩種方式擇一:
- Windows (最簡單): 從 最新版本
下載
LineBackupToDiscord-<版本>.zip並解壓縮,不需要安裝 Python - 從原始碼執行 (Windows / Linux / macOS): clone 此專案後,先運行一次
run.bat(Windows) 或run.sh(Linux / macOS), 它會自動建立 Python 環境並產生config.yml,接著程式會自動結束
- Windows (最簡單): 從 最新版本
下載
- 開啟
config.yml並遵照內文完成填寫,請參考 這裡,建議使用 Notepad++ 來編輯檔案 - 運行
LineBackupToDiscord.exe來啟動機器人,若從原始碼執行則運行run.bat/run.sh - 設定 LINE Webhook 指向你的伺服器,請參考 這裡
- 邀請 Discord 機器人至你的 Discord 伺服器,並將 LINE 機器人加入你的 LINE 群組
- 在 LINE 群組中 tag 機器人 (
@<你的 LINE 機器人名稱>),並在回覆中點選邀請好了,機器人會另外傳送一則只有指令的訊息,方便你長按複製 6 位數的綁定碼, 此綁定碼僅能使用一次,並將於 5 分鐘後過期,過期前重複請求皆會取得同一組綁定碼 - 在你想要備份的 Discord 頻道中輸入
/link <綁定碼> - 完成!之後 LINE 群組中的每則新訊息都會備份到該 Discord 頻道!
| 位置 | 指令 | 說明 |
|---|---|---|
| LINE | @<機器人名稱> |
tag 機器人以開始綁定流程並取得綁定碼 |
| LINE | !ID |
顯示目前 LINE 群組的 ID |
| Discord | /link <綁定碼> |
將此頻道與 LINE 群組綁定,並開始備份訊息 |
| Discord | /unlink |
解除此頻道與 LINE 群組的綁定,並停止備份 |
| Discord | /about |
查看機器人的詳細資訊,以及此頻道目前綁定的 LINE 群組 |
| Discord | /help |
查看機器人的使用方式 |
# ++--------------------------------++
# | LineBackupToDiscord (MIT LICENSE)|
# | Made by LD v0.1.1 |
# ++--------------------------------++
# Line Channel Access Token & Secret
# You can get it from https://developers.line.biz/console/
line_channel_access_token: ''
line_channel_secret: ''
# Discord Bot token
# You can get it from https://discord.com/developers/applications
discord_bot_token: ''
# Backend server configuration, aka the webhook server port for LINE.
# If you change port, make sure to change the port in your reverse proxy(ngrok etc..) as well.
webhook_port: 5000
# Downloads folder settings.
# Pictures, videos, audios, files, stickers and emojis are saved in the downloads folder,
# pick how to manage it:
# 'unlimited' - Keep every file forever (default)
# 'size_limit' - Keep the folder under downloads_max_size_mb, the least recently used files
# are removed automatically when it gets bigger than that
# 'instant_burn' - Remove pictures, videos, audios and files right after they are sent to Discord.
# Stickers and emojis are kept as a cache, limited by downloads_max_size_mb
downloads_mode: 'unlimited'
# Max size of the downloads folder in MB, used when downloads_mode is 'size_limit' or 'instant_burn'
downloads_max_size_mb: 1024
# (Optional settings)
# You can fill in your own bot invite link and hosted by information
# This will be shown when someone types /about
# Noted that if you share your bot invite link, anyone can invite your bot to their server
bot_hosted_by: 'PlayfunI Network'
line_bot_invite_link: ''
discord_bot_invite_link: ''圖片、影片、音檔、檔案及貼圖長時間累積下來會佔用不少硬碟空間,你可以在 config.yml 中透過 downloads_mode 選擇 downloads
資料夾的管理方式:
downloads_mode |
說明 |
|---|---|
unlimited (預設) |
永久保留所有檔案 |
size_limit |
將資料夾維持在 downloads_max_size_mb MB 以下,超過時會優先刪除最久沒被使用的檔案,貼圖包會整包一起刪除。機器人啟動時也會檢查一次 |
instant_burn |
圖片、影片、音檔及檔案傳送至 Discord 後立即刪除。貼圖包及 LINE 表情貼每次傳送時都會重複使用,因此會保留作為快取,並和 size_limit 一樣受 downloads_max_size_mb 限制 |
- 前往 LINE Developers 並使用你的 LINE 帳號登入
- 如果你沒有 Business ID,請按照官網的指示建立一個
- 點擊
Create a new provider - 填寫完需要的資料後點擊
Create - 點擊
Create a new channel並選擇Messaging API的分類 - 填寫完需要的資料後點擊
Create - 現在你可以在
Basic settings找到你的channel secret以及在Messaging API找到channel access token,點擊Issue來複製
註:請確保你在 LINE 機器人設定中的 Messaging API > LINE Official Account features, 勾選
Allow bot to join group chats 選項,並 取消勾選 Auto-reply messages 選項
- 前往 LINE Developers 並使用你的 LINE 帳號登入
- 點擊你要使用的
channel application - 選擇
Messaging API分類,找到Webhook URL並點擊Edit - 貼上你的 HTTPS 公開網址並在尾處加上
/callback,例如https://your-domain.ngrok-free.app/callback - 點擊
Save,接著點擊Verify確認機器人可以正常連線 (機器人必須處於運行中) - 在
Webhook URL底下勾選Use webhook
註:LINE Webhook 僅適用於 HTTPS 協議,而機器人會監聽 webhook_port (預設為 5000),所以你需要一個能將 HTTPS 網址轉發到該
port 的反向代理。如果你不知道如何申請,可以使用 ngrok
創建一個簡單的導向服務,請參考 這裡的教學
- 前往 Discord Developer Portal 並使用你的 Discord 帳號登入
- 點擊
New Application - 幫此機器人取名 (例如
Line訊息備份) 後點擊Create - 點擊左側列表的
Bot - 點擊
Reset Token來取得並複製你的 bot token - 邀請機器人:前往
OAuth2>URL Generator,勾選bot及applications.commands,並給予Manage Webhooks權限 (執行/link時機器人會在頻道中建立 webhook)。開啟產生的網址即可邀請機器人至你的伺服器,你也可以將此網址填入config.yml的discord_bot_invite_link
- 前往 Ngrok 註冊一個帳號並登入
- 前往 Domains Dashboard,你會在這裡找到一個免費的固定網域 (或自行建立一個),
它應該會長這樣
something-random-idontknow.ngrok-free.app - 從 這裡 下載並安裝 ngrok
- 加入你的授權金鑰,你可以在 這裡 找到
ngrok config add-authtoken <your_auth_token>
- 啟動通道,把
<domain_name>替換為你的網域名稱,若你有更改webhook_port,請一併把5000替換掉ngrok http --url=<domain_name> 5000
- 完成!現在你的 Webhook URL 就是
https://<domain_name>/callback
- Fork 這個專案
- 複製你剛剛 Fork 的專案至本地
- 安裝 uv 並執行
uv sync來建立環境 - 建立新的分支
- 盡情發揮你的能力,使用
uv run main.py來運行機器人 - Commit / Push 你的程式碼
- 建立新的 Pull Request
- 等待回覆
本專案使用 uv 管理套件 (pyproject.toml / uv.lock),並由 Renovate 自動追蹤套件更新。
requirements.txt 是透過 uv export --no-hashes --frozen > requirements.txt 從 uv.lock 產生的,請勿手動修改。
想要打包成執行檔嗎?請參考 build_executable。發布版本的壓縮檔由 GitHub Actions 在 Windows 上自動打包, 請參考 這裡。
- FastAPI + Uvicorn 用來架設 Webhook 伺服器
- LINE Messaging API SDK 用來與 LINE API 溝通
- discord.py 用來與 Discord API 及 Webhook 溝通
- Pydantic 用來驗證資料格式
- PyYAML 用來讀取 config.yml 檔案
- requests 用來傳送 HTTP 請求
- Pillow 用來將動態貼圖轉換為 GIF
- PyInstaller 用來打包執行檔
- 每行不超過100個字元
- 使用
snake_case命名變數及函式 - 在檔案尾處加上一個空行
- 最佳化程式碼並移除不必要的import
- Google style TODO註解
- 使用 Sphinx Docstring 進行函式註解
- 提交請求時請使用 Conventional Commits 格式,並全英文撰寫,例如
- feat: your commit messages here
- fix: your commit messages here
- refactor: your commit messages here
- build: your commit messages here
- docs: your commit messages here
如果你有任何建議或是發現了任何問題,請在 Issues 提交你的意見,我會盡快回覆你!
此專案的版權規範採用 MIT License - 至 LICENSE 查看更多相關聲明
