Delay-synchronization#18
Merged
TaranDahl merged 3 commits intoJun 12, 2026
Merged
Conversation
Contributor
Author
|
solved #8 |
Collaborator
|
我觉得补发是不是应该同时检查时间(比如30分钟分钟)和条数 |
Contributor
Author
|
已修复,详见 commit 10c20e9。
Fixed in 10c20e9.
|
WhiteFeather127
added a commit
to WhiteFeather127/QQ-DC-Bridge
that referenced
this pull request
Jun 12, 2026
Both branches added code after _on_discord_message: - HEAD: _on_discord_dm method - upstream/master: _last_processed_id persistence (PR Phobos-developers#18) Kept both: persistence at end of _on_discord_message, _on_discord_dm after it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Discord 消息补发机制
概述
当 VPN 断线、网络抖动或 Discord Gateway 偶发断开时,Bot 会丢失断连期间频道中发送的消息。本机制通过 持久化记录最后处理的消息 ID,在重连后自动拉取并补发漏掉的消息。
解决的问题
discord.pyresume 成功则不丢失工作原理
关键设计
on_connectvson_resumedon_resumed:session 恢复成功时触发,此时 Gateway 已自动重放漏掉的事件,不需要手动补发on_connect:新 session 建立时触发,之前断开期间的事件已永久丢失,此时才需要补发limit=50防刷屏保护Snowflake 数值比较去重
int(msg_id) <= int(_last_processed_id)直接判断是否已处理持久化到文件
data/discord_last_msg_id.txt相关文件
src/adapters/discord/adapter.pysrc/main.pydata_dir参数data/discord_last_msg_id.txt日志示例
Discord Message Catch‑Up Mechanism
Overview
When a VPN disconnects, network jitter occurs, or the Discord Gateway experiences an occasional disconnect, the bot will miss messages sent in the channel during the downtime. This mechanism persistently records the ID of the last processed message, and automatically fetches and processes any missed messages after reconnecting.
Problems Solved
discord.pyresumes successfullyHow It Works
Key Design Points
on_connectvson_resumedon_resumed: triggered when a session is successfully resumed. The Gateway has already replayed missed events, so manual catch‑up is NOT required.on_connect: triggered when a new session is established. Events sent during the disconnection are permanently lost, so catch‑up is required.limit=50Anti‑Flood ProtectionSnowflake Numeric Comparison for Deduplication
int(msg_id) <= int(_last_processed_id)directly determines whether a message has already been processed.Persistent File Storage
data/discord_last_msg_id.txtRelated Files
src/adapters/discord/adapter.pysrc/main.pydata_dirparameterdata/discord_last_msg_id.txtLog Examples