so trying to run my bot on an AWS ec2 server and it crashes overnight while I am asleep so when i wake up the next morning I find my bot down. when I check what caused the crash I am always greeted to
events.js:173
throw err; // Unhandled 'error' event
^
Error [ERR_UNHANDLED_ERROR]: Unhandled error. ([object Object])
at Client.emit (events.js:171:17)
at WebSocketConnection.onError (/home/ec2-user/kalina/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:374:17)
at WebSocket.onError (/home/ec2-user/kalina/node_modules/ws/lib/event-target.js:128:16)
at WebSocket.emit (events.js:182:13)
at _receiver.cleanup (/home/ec2-user/kalina/node_modules/ws/lib/websocket.js:211:14)
at Receiver.cleanup (/home/ec2-user/kalina/node_modules/ws/lib/receiver.js:557:13)
at WebSocket.finalize (/home/ec2-user/kalina/node_modules/ws/lib/websocket.js:206:20)
at TLSSocket.emit (events.js:182:13)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
from the few friends I have talked to this isn't a problem with my code. is anyone else experiencing this?
a sample of the code I am using:
bot.on('ready', () => {
cron.schedule('0 5,11 * * 1', function(){
sendMessageBat(embed6);
});
cron.schedule('30 7,13 * * 1', function(){
sendMessageBat(embed7);
});
cron.schedule('0 8,14 * * 1', function(){
sendMessageBat(embed8);
});
function sendMessageBat(msg) {
fs.readFile('battery.json', 'utf8', function readFileCallback(err, data) {
if (err) {
} else {
var dict = JSON.parse(data);
for(var serverID in dict){
var channelIDs = dict[serverID];
for(var i in channelIDs){
bot.guilds.get(serverID).channels.get(channelIDs[i]).send(msg);
}
}
}
});
}
})
I am running 2 of these and the other part of the bot is just a command handler/section
i forgot to mention that the versions i am running are the latest of everything
You should definitely handle the error event, just like the error is telling you.
Duplicated of #2523 and many other issues, this is not an issue with the library but rather in your side, handle your error event (mentioned in the linked issue) and this should not longer crash.