Discord-user-bots icon indicating copy to clipboard operation
Discord-user-bots copied to clipboard

Random disconnects

Open DarrenRainey opened this issue 3 years ago • 6 comments

Currently the bot seems to randomly disconnect when running the following code and fails to autoreconnect

const Discord = require("discord-user-bots");
const client = new Discord.Client("TOKEN");

client.on.ready = function () {
    console.log("Client online!");
};

client.on.presence_update = function (user) {
        console.log(user);
};

DarrenRainey avatar Sep 07 '21 23:09 DarrenRainey

Can you please specify what happens? When testing I didn't see the any disconnect Error message and when setting an interval loop to test the ready state of the bot WebSocket it was always open. If you mean it doesn't call the presence_update function, then it's just that there aren't many people changing their status.

Sopur avatar Sep 08 '21 16:09 Sopur

I'll have to do some more testing but what I found was after a while the presence_update function would just stop working I've tested this with my alt account changing status and after say 15 minutes it would stop showing any presence updates.

DarrenRainey avatar Sep 12 '21 13:09 DarrenRainey

Do any other events work or is it just presence_update?

Sopur avatar Sep 13 '21 15:09 Sopur

Thank you for this package, @Sopur!

I'm not sure if this is related, but I'm having the same issues with on.message_create when I let it run for a while.

Running dockerized and reproducible on both local machine and an EC2 instance, with it normally dying off in about an hour.

Latest test shows the app working as expected for 46 minutes, before it stops receiving new message events. No errors, heartbeat_sent and heartbeat_received continue to be triggered in the mean time.

DeividasJackus avatar Oct 14 '21 15:10 DeividasJackus

Correction to my statement above: it appears that after the hang up heartbeats are only sent, not received. In my case the issue is the websocket being unexpectedly closed by the server as an hour or two pass by.

Could this be pointing to an issue with heartbeats?

In the mean time, the poor man's short-term fix for me is listening to discord_disconnect and simply restarting the process.

DeividasJackus avatar Oct 14 '21 21:10 DeividasJackus

Thank you. I will look into this.

Sopur avatar Oct 16 '21 18:10 Sopur

I've encountered the same issue. I'll try to submit a fix in the coming hours or days. This wrapper has been incredibly nice to use so I'd really like to support it.

lf94 avatar Feb 21 '23 01:02 lf94

One issue could be that the heartbeat is reporting back a d of null, when it should match how many messages have passed, which I determined through some trial-and-error. ~~I think there should be a reply message back to heartbeat reply (so: discord_heartbeat -> your_reply -> discord_heartbeat_conf)~~ Nevermind. Double checked and that's not the case.

~~There also appears to be an "/ack" request once in awhile. <- waiting to double confirm this too.~~ Appears to not be necessary either. If it's really all about an incrementing d then that's nice :slightly_smiling_face: I'll run it over night.

Edit: it appears this was not the solution either. I'm going to just leave discord open with a new account and record what it does now.

lf94 avatar Feb 21 '23 01:02 lf94

So yeah, it appears Discord will auto-disconnect if there's little to no activity, even with heartbeats, and restart the websocket in their official client. So @DeividasJackus 's "poor-man's" solution is actually the right one!

lf94 avatar Feb 21 '23 15:02 lf94

Should the library do this for devs or should devs be aware?

lf94 avatar Feb 21 '23 17:02 lf94

Thank you for bringing this to my attention again. I will add logic to automatically reconnect when needed, while also triggering a discord_reconnect event.

Sopur avatar Feb 21 '23 22:02 Sopur

Could you leave the issue open until it's done? Just so I get the notification - I'd like to remove the reconnect code I already have when this is added. (The issue is also still pinned.)

lf94 avatar Feb 21 '23 23:02 lf94

Hi, have there been any updates on the status of this fix? I have also experienced the same issue.

wowkster avatar Feb 27 '23 12:02 wowkster

Fixed as of version 1.6.0.

Sopur avatar Feb 27 '23 21:02 Sopur