discordjs / discord.js

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

events.js:160 Unhandled 'error' event #1002

Closed rvddesign closed 7 years ago

rvddesign commented 7 years ago

Running on an older version of Discord (not sure where to check the version number), however recently one of the hosted bots ends up disconnecting and reconnecting itself many times over using the following piece of code:

bot.on('disconnected', function() {\n
    console.log('Disconnected!');\n
    bot.login(AuthDetails.email, AuthDetails.password);\n
});

And eventually (or straight away when manually restarting it) it will display the following error message on the console:

events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: Invalid session
    at WebSocket.websocket.onclose (C:\Path\Discord\node_modules\discord.js\lib\Client\InternalClient.js
:1791:12)
    at WebSocket.onClose (C:\Path\Discord\node_modules\ws\lib\WebSocket.js:446:14)
    at emitTwo (events.js:106:13)
    at WebSocket.emit (events.js:191:7)
    at WebSocket.cleanupWebsocketResources (C:\Path\Discord\node_modules\ws\lib\WebSocket.js:950:8)
    at emitNone (events.js:91:20)
    at TLSSocket.emit (events.js:185:7)
    at endReadableNT (_stream_readable.js:973:12)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

It appears to be frequently affecting one of the first bots we wrote, but doesn't appear to affect the later ones which were written in a similar fashion and are running on the same version. Running 3 of them at the same time, and they never had this issue before, until recently. How could I resolve this, or was something changed in the Discord APIs?

I couldn't find any information about it, so I thought I'd drop this here.

devsnek commented 7 years ago

can you check the version using npm list discord.js (i'm suspecting v8), also feel free to join us for quicker support here

rvddesign commented 7 years ago

Version displayed appears to be v8.0.0

-- discord.js@8.0.0  (git://github.com/hydrabolt/discord.js.git#422fffdbfb4cc17
7a4d98b5c4a1a473fad52663c)
devsnek commented 7 years ago

well as much as i hate to say this, v8 is not supported anymore, and there have been large changes in how the api works. I would say your best bet is updating to the latest version, which is v10. you can find some docs here. I should also warn you that in the update from v8 => v9 we changed the lib to OOP.

rvddesign commented 7 years ago

Hm, yeah.. there are however some large changes breaking some important features the current bot is able to do with v8, that's why I hadn't updated yet. It was actually running fine and without problems until recently, and since it appears to only be affecting mainly one of the bots (the other two had only showed the same issue once or twice, while this is very frequent), I thought I'd check.

Thanks anyways