discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.39k stars 3.97k forks source link

Bot unable to send messages after some time #3136

Closed niekcandaele closed 5 years ago

niekcandaele commented 5 years ago

Please describe the problem you are having in as much detail as possible:

After some long-ish time (8 hours is the lowest i've seen) the bot stops being able to send messages. As far as I can tell, only sending messages stops working. Every other function I tested still works.

Include a reproducible code sample here, if possible:

I've tried to debug this in several ways but haven't found a solution. After restarting the process, sending messages works as expected so I know that permissions are OK.

2019-03-09T00:49:31.629Z - info: DISCORD DEBUG - [ws] [connection] Sending a heartbeat
2019-03-09T00:49:31.771Z - info: DISCORD DEBUG - [ws] [connection] Heartbeat acknowledged, latency of 142ms

@botuser eval console.log('test')

@botuser eval console.log(client.channels.get('521825197666467840').id)

@botuser eval client.channels.get('521825197666467840').send('works').then(r => console.log('success - ' + r)).catch(e => console.log('fail - ' + e))

Further details:

I've only seen this happen in the production instance and have not been able to reproduce in a dev environment. Testing on master is not possible because of that.

Thank you!

niekcandaele commented 5 years ago

Small update:

Today, the bot actually went offline. I saw this message in the logs: 2019-03-11T22:34:11.166Z - info: DISCORD DEBUG - [ws] [connection] Tried to send packet [object Object] but no WebSocket is available!

I'm not sure if it's related to my original issue.

iTURTL3 commented 5 years ago

I'm having the same issue on some of my bots, the bot is fine for a few hours then stops sending messages.

niekcandaele commented 5 years ago

Follow up

I noticed that I was GETting a particular role many times in my application, I started caching the response in Redis and I have not seen this problem since. Might be anecdotal...

iCrawl commented 5 years ago

This has been inactive for quite some time, please reopen if this issue still persists (on master).