Issue
Is hosting a discord.js
bot. The bot’s function is using fs.watchFile
and fs.readFile
to monitoring changes in a text files and send Discord embed that summarises the data entries within a target.txt
file. However, the bot always crash after running for a few hours and throwing process.nextTick error:
C:\Users\Administrator\Desktop\Bot\node_modules\ws\lib\websocket.js:1035
process.nextTick(resume, websocket._socket);
TypeError: process.nextTick is not a function
at Receiver.receiverOnConclude (C:\Users\Administrator\Desktop\Bot\node_modules\ws\lib\websocket.js:1035:11)
at Receiver.emit (node:events:526:28)
at Receiver.controlMessage (C:\Users\Administrator\Desktop\Bot\node_modules\ws\lib\receiver.js:576:14)
at Receiver.getData (C:\Users\Administrator\Desktop\Bot\node_modules\ws\lib\receiver.js:423:42)
at Receiver.startLoop (C:\Users\Administrator\Desktop\Bot\node_modules\ws\lib\receiver.js:148:22)
at Receiver._write (C:\Users\Administrator\Desktop\Bot\node_modules\ws\lib\receiver.js:83:10)
at writeOrBuffer (node:internal/streams/writable:389:12)
at _write (node:internal/streams/writable:330:10)
at Receiver.Writable.write (node:internal/streams/writable:334:10)
at TLSSocket.socketOnData (C:\Users\Administrator\Desktop\Bot\node_modules\ws\lib\websocket.js:1187:35)
All these code is working except getting the process.nextTick’s TypeError every few hours, unsure which part caused the error…or can the error be bypass by monkey patching?
Solution
Did not find a way to fix the discord.js script from getting that process.nextTick
error but pm2
npm package can at least prevent script from stopping.
How to use pm2 to autorestart my discord bot
Answered By – Peanut Jams
Answer Checked By – Marilyn (AngularFixing Volunteer)