Discord 頻道同步機器人Discord Channel Sync Bot
把指定來源頻道的訊息(文字與圖片)自動轉發到一個目標頻道,來源訊息被編輯時也會同步更新。適合跨頻道公告、備份或自動轉發。A Node.js bot that forwards messages (text and images) from selected source channels to one target channel, and updates the forwarded copy when the source message is edited. Useful for cross-channel announcements, backups and auto-forwarding.
原始碼未公開Source is private
如何運作How it works
讀取設定並登入
index.js 從 config.json 讀取 CHANNEL_LISTEN(來源頻道)與 CHANNEL_POST(目標頻道);token 為 null 時在終端機以 readline 詢問,Token 不必寫進檔案,再以 discord.js 登入。保持上線
同時載入 keep_alive.js,在 8080 埠以內建 http 模組回應 I'm alive,方便部署在 Replit、Glitch 等平台並搭配外部監控防止休眠,也可用 pm2 常駐。監聽新訊息
收到 MessageCreate 事件後,若訊息來自 CHANNEL_LISTEN 內的頻道,就轉發到 CHANNEL_POST;有附件時連同第一個附件的 URL 一起送出,否則只送文字。同步編輯
收到 MessageUpdate 事件後,在目標頻道以舊訊息 ID 往後查詢取得對應的轉發訊息,並改成新的內容(含附件)。
架構Architecture
flowchart LR
S[來源頻道 CHANNEL_LISTEN] -- MessageCreate / MessageUpdate --> G[Discord Gateway]
G --> B[index.js discord.js Client]
C[config.json] --> B
T[終端機輸入 Token] -. token 為 null .-> B
B -- send / edit --> P[目標頻道 CHANNEL_POST]
K[keep_alive.js HTTP 8080] -.-> H[託管平台 Replit / Glitch]技術Tech stack
Node.jsdiscord.js 14JavaScriptpm2