Anyone Know how to catch this error so the bot doesn't go offline?

Error: WebSocket was closed before the connection was established
at WebSocket.close (C:\Users\Admin\Desktop\Discord Bot 3\node_modules\ws\lib\websocket.js:287:7)
at WebSocketShard.destroy (C:\Users\Admin\Desktop\Discord Bot 3\node_modules\discord.js\src\client\websocket\WebSocketShard.js:728:27)
at WebSocketShard._send (C:\Users\Admin\Desktop\Discord Bot 3\node_modules\discord.js\src\client\websocket\WebSocketShard.js:668:12)
at WebSocketShard.processQueue (C:\Users\Admin\Desktop\Discord Bot 3\node_modules\discord.js\src\client\websocket\WebSocketShard.js:694:12)
at WebSocketShard.send (C:\Users\Admin\Desktop\Discord Bot 3\node_modules\discord.js\src\client\websocket\WebSocketShard.js:656:10)
at WebSocketManager.broadcast (C:\Users\Admin\Desktop\Discord Bot 3\node_modules\discord.js\src\client\websocket\WebSocketManager.js:313:53)
at ClientPresence.set (C:\Users\Admin\Desktop\Discord Bot 3\node_modules\discord.js\src\structures\ClientPresence.js:25:22)
at ClientUser.setPresence (C:\Users\Admin\Desktop\Discord Bot 3\node_modules\discord.js\src\structures\ClientUser.js:120:33)
at ClientUser.setActivity (C:\Users\Admin\Desktop\Discord Bot 3\node_modules\discord.js\src\structures\ClientUser.js:167:17)
at Timeout._onTimeout (C:\Users\Admin\Desktop\Discord Bot 3\index.js:54:19)
Emitted 'error' event on WebSocket instance at:
at emitErrorAndClose (C:\Users\Admin\Desktop\Discord Bot 3\node_modules\ws\lib\websocket.js:1016:13)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Error: WebSocket was closed before the connection was established
at WebSocket.close (C:\Users\Admin\Desktop\Discord Bot 3\node_modules\ws\lib\websocket.js:287:7)
at WebSocketShard.destroy (C:\Users\Admin\Desktop\Discord Bot 3\node_modules\discord.js\src\client\websocket\WebSocketShard.js:728:27)
at WebSocketShard._send (C:\Users\Admin\Desktop\Discord Bot 3\node_modules\discord.js\src\client\websocket\WebSocketShard.js:668:12)
at WebSocketShard.processQueue (C:\Users\Admin\Desktop\Discord Bot 3\node_modules\discord.js\src\client\websocket\WebSocketShard.js:694:12)
at WebSocketShard.send (C:\Users\Admin\Desktop\Discord Bot 3\node_modules\discord.js\src\client\websocket\WebSocketShard.js:656:10)
at WebSocketManager.broadcast (C:\Users\Admin\Desktop\Discord Bot 3\node_modules\discord.js\src\client\websocket\WebSocketManager.js:313:53)
at ClientPresence.set (C:\Users\Admin\Desktop\Discord Bot 3\node_modules\discord.js\src\structures\ClientPresence.js:25:22)
at ClientUser.setPresence (C:\Users\Admin\Desktop\Discord Bot 3\node_modules\discord.js\src\structures\ClientUser.js:120:33)
at ClientUser.setActivity (C:\Users\Admin\Desktop\Discord Bot 3\node_modules\discord.js\src\structures\ClientUser.js:167:17)
at Timeout._onTimeout (C:\Users\Admin\Desktop\Discord Bot 3\index.js:54:19)
Emitted 'error' event on WebSocket instance at:
at emitErrorAndClose (C:\Users\Admin\Desktop\Discord Bot 3\node_modules\ws\lib\websocket.js:1016:13)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
2 Replies
d.js toolkit
d.js toolkit12mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by staff
Skylife
Skylife12mo ago
use try {} catch(){} finally and handle your error accordingly
Want results from more Discord servers?
Add your server