bwmarrin / discordgo

(Golang) Go bindings for Discord
BSD 3-Clause "New" or "Revised" License
5.11k stars 813 forks source link

How to use Discord's reconnection mechanism? #1502

Open linliyuan opened 8 months ago

linliyuan commented 8 months ago

I found that there is relevant information in the documentation https://discord.com/developers/docs/topics/gateway#resuming, but there is no corresponding implementation method in the third-party package. Can this recovery mechanism be added? Currently, sessionID, sequence, and gateway are all private, which prevents me from obtaining the last sequence of websocket events. The adjustments needed are quite large. I saw that there were several merge requests related to this, what was the reason for finally closing them? merge requests: https://github.com/bwmarrin/discordgo/pull/1327 https://github.com/bwmarrin/discordgo/pull/1115

And the following piece of code is quite strange, the reconnection judgment is before ready, which inevitably leads to the sessionID and sequence in the newly created session being 0. Send Op 6 Resume Packet can only possibly be executed in the case of a reconnect.

image

The current background is: the program cannot always run normally. If the service encounters an exception, I hope that the unprocessed data during the restart can be re-obtained through the recovery mechanism.