bot crash after some hours #7

Closed
opened 2025-11-20 04:14:21 -05:00 by saavagebueno · 16 comments
Owner

Originally created by @HamzaJarane on GitHub (Oct 14, 2022).

/root/game-server-watcher/node_modules/discord.js/src/client/actions/MessageCreate.js:11
const existing = channel.messages.cache.get(data.id);
^

TypeError: Cannot read properties of undefined (reading 'cache')
at MessageCreateAction.handle (/root/game-server-watcher/node_modules/discord.js/src/client/actions/MessageCreate.js:11:41)
at Object.module.exports [as MESSAGE_CREATE] (/root/game-server-watcher/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/root/game-server-watcher/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
at WebSocketShard.onPacket (/root/game-server-watcher/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/root/game-server-watcher/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
at WebSocket.onMessage (/root/game-server-watcher/node_modules/ws/lib/event-target.js:132:16)
at WebSocket.emit (node:events:513:28)
at Receiver.receiverOnMessage (/root/game-server-watcher/node_modules/ws/lib/websocket.js:1068:20)
at Receiver.emit (node:events:513:28)
at Receiver.dataMessage (/root/game-server-watcher/node_modules/ws/lib/receiver.js:517:14)

node.js: v16
discord.js: 12.5.3
os: ubuntu 20.04 (self hosting)

tried to run it with nodemon/pm2/screen and still crash after some hours

Originally created by @HamzaJarane on GitHub (Oct 14, 2022). /root/game-server-watcher/node_modules/discord.js/src/client/actions/MessageCreate.js:11 const existing = channel.messages.cache.get(data.id); ^ TypeError: Cannot read properties of undefined (reading 'cache') at MessageCreateAction.handle (/root/game-server-watcher/node_modules/discord.js/src/client/actions/MessageCreate.js:11:41) at Object.module.exports [as MESSAGE_CREATE] (/root/game-server-watcher/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32) at WebSocketManager.handlePacket (/root/game-server-watcher/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31) at WebSocketShard.onPacket (/root/game-server-watcher/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22) at WebSocketShard.onMessage (/root/game-server-watcher/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10) at WebSocket.onMessage (/root/game-server-watcher/node_modules/ws/lib/event-target.js:132:16) at WebSocket.emit (node:events:513:28) at Receiver.receiverOnMessage (/root/game-server-watcher/node_modules/ws/lib/websocket.js:1068:20) at Receiver.emit (node:events:513:28) at Receiver.dataMessage (/root/game-server-watcher/node_modules/ws/lib/receiver.js:517:14) node.js: v16 discord.js: 12.5.3 os: ubuntu 20.04 (self hosting) tried to run it with nodemon/pm2/screen and still crash after some hours
Author
Owner

@a-sync commented on GitHub (Oct 15, 2022):

from the trace it seems like the error originates from discord.js. it tries to send a message while the instance is deconstructed/disconnected and when that fails it crashes the entire service.

are you using the same bot token anywhere else perhaps? (or have multiple instances of the bot running with the same token?)
do you have debug mode enabled? (DBG env var)
can you see any discord-bot ERROR messages in the output?

@a-sync commented on GitHub (Oct 15, 2022): from the trace it seems like the error originates from discord.js. it tries to send a message while the instance is deconstructed/disconnected and when that fails it crashes the entire service. are you using the same bot token anywhere else perhaps? (or have multiple instances of the bot running with the same token?) do you have debug mode enabled? (`DBG` env var) can you see any `discord-bot ERROR` messages in the output?
Author
Owner

@HamzaJarane commented on GitHub (Oct 15, 2022):

No, I don't use it anywhere, anyways I regenerate the token and still happening
No, but I can enable it and watch the bot
Yes I can

@HamzaJarane commented on GitHub (Oct 15, 2022): No, I don't use it anywhere, anyways I regenerate the token and still happening No, but I can enable it and watch the bot Yes I can
Author
Owner

@a-sync commented on GitHub (Oct 15, 2022):

copy paste those discord-bot ERROR messages please :)

@a-sync commented on GitHub (Oct 15, 2022): copy paste those discord-bot ERROR messages please :)
Author
Owner

@HamzaJarane commented on GitHub (Oct 15, 2022):

hello, it doesn't print any discord-bot errors except this
image
edit:
I also regenerate the token more than once but still happening

@HamzaJarane commented on GitHub (Oct 15, 2022): hello, it doesn't print any discord-bot errors except this ![image](https://user-images.githubusercontent.com/70551889/196009609-2ac46543-6ee2-407a-b5c0-7c231ee019fa.png) edit: I also regenerate the token more than once but still happening
Author
Owner

@a-sync commented on GitHub (Oct 16, 2022):

hello, it doesn't print any discord-bot errors except this image

is that the entire message? if not, please make sure to include the bottom part, it should show where the error originates from.

just a side note: u don't need multiple tokens, just one with the proper permissions. i asked because using the same token with multiple apps can cause issues.

@a-sync commented on GitHub (Oct 16, 2022): > hello, it doesn't print any discord-bot errors except this ![image](https://user-images.githubusercontent.com/70551889/196009609-2ac46543-6ee2-407a-b5c0-7c231ee019fa.png) is that the entire message? if not, please make sure to include the bottom part, it should show where the error originates from. _just a side note: u don't need multiple tokens, just one with the proper permissions. i asked because using the same token with multiple apps can cause issues._
Author
Owner

@a-sync commented on GitHub (Oct 16, 2022):

some searching reveals that this specific error might be a discord.js v12 bug, but i have never experienced it.
(i have been running gsw on different hosts with 10+ servers for many weeks of uptime without any issues)

worst case it will be fixed with the next major gsw update when moving to node16, discord.js is also upgraded.
all sdk calls should be able to fail safely in gsw, but this is not true obviously, so if we can find the origin of the error i can also try to add a quick fix for this on the stable branch.

@a-sync commented on GitHub (Oct 16, 2022): some searching reveals that this specific error might be a discord.js v12 bug, but i have never experienced it. (i have been running gsw on different hosts with 10+ servers for many weeks of uptime without any issues) worst case it will be fixed with the next major gsw update when moving to node16, discord.js is also upgraded. all sdk calls should be able to fail safely in gsw, but this is not true obviously, so if we can find the origin of the error i can also try to add a quick fix for this on the stable branch.
Author
Owner

@HamzaJarane commented on GitHub (Oct 16, 2022):

hello, it doesn't print any discord-bot errors except this image

is that the entire message? if not, please make sure to include the bottom part, it should show where the error originates from.

just a side note: u don't need multiple tokens, just one with the proper permissions. i asked because using the same token with multiple apps can cause issues.

Yes its the entire message, if I include the last line it will be just root@vps-csi23821e:~#
Yes, I'm sure I'm using it for only 1 app, if I regenerate the token shouldn't that automatically disconnect all other apps?

@HamzaJarane commented on GitHub (Oct 16, 2022): > > hello, it doesn't print any discord-bot errors except this ![image](https://user-images.githubusercontent.com/70551889/196009609-2ac46543-6ee2-407a-b5c0-7c231ee019fa.png) > > is that the entire message? if not, please make sure to include the bottom part, it should show where the error originates from. > > _just a side note: u don't need multiple tokens, just one with the proper permissions. i asked because using the same token with multiple apps can cause issues._ Yes its the entire message, if I include the last line it will be just **root@vps-csi23821e:~#** Yes, I'm sure I'm using it for only 1 app, if I regenerate the token shouldn't that automatically disconnect all other apps?
Author
Owner

@HamzaJarane commented on GitHub (Oct 16, 2022):

some searching reveals that this specific error might be a discord.js v12 bug, but i have never experienced it. (i have been running gsw on different hosts with 10+ servers for many weeks of uptime without any issues)

worst case it will be fixed with the next major gsw update when moving to node16, discord.js is also upgraded. all sdk calls should be able to fail safely in gsw, but this is not true obviously, so if we can find the origin of the error i can also try to add a quick fix for this on the stable branch.

I will try to run it with node js 12 and give you a feedback

@HamzaJarane commented on GitHub (Oct 16, 2022): > some searching reveals that this specific error might be a discord.js v12 bug, but i have never experienced it. (i have been running gsw on different hosts with 10+ servers for many weeks of uptime without any issues) > > worst case it will be fixed with the next major gsw update when moving to node16, discord.js is also upgraded. all sdk calls should be able to fail safely in gsw, but this is not true obviously, so if we can find the origin of the error i can also try to add a quick fix for this on the stable branch. I will try to run it with node js 12 and give you a feedback
Author
Owner

@a-sync commented on GitHub (Oct 16, 2022):

it's more about the sdk version included in gsw then the node version its running on. but u could give it a try

@a-sync commented on GitHub (Oct 16, 2022): it's more about the sdk version included in gsw then the node version its running on. but u could give it a try
Author
Owner

@HamzaJarane commented on GitHub (Oct 16, 2022):

Hello, it was working for almost 10h then crashes with this log:
image
/root/game-server-watcher/node_modules/discord.js/src/client/actions/MessageCreate.js:11
const existing = channel.messages.cache.get(data.id);
^

TypeError: Cannot read property 'cache' of undefined
at MessageCreateAction.handle (/root/game-server-watcher/node_modules/discord.js/src/client/actions/MessageCreate.js:11:41)
at Object.module.exports [as MESSAGE_CREATE] (/root/game-server-watcher/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/root/game-server-watcher/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
at WebSocketShard.onPacket (/root/game-server-watcher/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/root/game-server-watcher/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
at WebSocket.onMessage (/root/game-server-watcher/node_modules/ws/lib/event-target.js:132:16)
at WebSocket.emit (events.js:314:20)
at Receiver.receiverOnMessage (/root/game-server-watcher/node_modules/ws/lib/websocket.js:1068:20)
at Receiver.emit (events.js:314:20)
at Receiver.dataMessage (/root/game-server-watcher/node_modules/ws/lib/receiver.js:517:14)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! game-server-watcher@1.0.0 start: node ./dist/server.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the game-server-watcher@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-10-16T21_08_27_258Z-debug.log

npm log:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
2 info using npm@6.14.10
3 info using node@v12.20.1
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle game-server-watcher@1.0.0prestart: game-server-watcher@1.0.0
6 info lifecycle game-server-watcher@1.0.0
start: game-server-watcher@1.0.0
7 verbose lifecycle game-server-watcher@1.0.0start: unsafe-perm in lifecycle true
8 verbose lifecycle game-server-watcher@1.0.0
start: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/root/game-server-watcher/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
9 verbose lifecycle game-server-watcher@1.0.0start: CWD: /root/game-server-watcher
10 silly lifecycle game-server-watcher@1.0.0
start: Args: [ '-c', 'node ./dist/server.js' ]
11 silly lifecycle game-server-watcher@1.0.0start: Returned: code: 1 signal: null
12 info lifecycle game-server-watcher@1.0.0
start: Failed to exec start script
13 verbose stack Error: game-server-watcher@1.0.0 start: node ./dist/server.js
13 verbose stack Exit status 1
13 verbose stack at EventEmitter. (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack at EventEmitter.emit (events.js:314:20)
13 verbose stack at ChildProcess. (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:314:20)
13 verbose stack at maybeClose (internal/child_process.js:1022:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
14 verbose pkgid game-server-watcher@1.0.0
15 verbose cwd /root/game-server-watcher
16 verbose Linux 5.4.0-126-generic
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
18 verbose node v12.20.1
19 verbose npm v6.14.10
20 error code ELIFECYCLE
21 error errno 1
22 error game-server-watcher@1.0.0 start: node ./dist/server.js
22 error Exit status 1
23 error Failed at the game-server-watcher@1.0.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

Tried to run it with node v12.20.1 - npm v8.19.2

@HamzaJarane commented on GitHub (Oct 16, 2022): Hello, it was working for almost 10h then crashes with this log: ![image](https://user-images.githubusercontent.com/70551889/196059222-2a547d7a-68d5-4619-b72c-edab089c4e5e.png) /root/game-server-watcher/node_modules/discord.js/src/client/actions/MessageCreate.js:11 const existing = channel.messages.cache.get(data.id); ^ TypeError: Cannot read property 'cache' of undefined at MessageCreateAction.handle (/root/game-server-watcher/node_modules/discord.js/src/client/actions/MessageCreate.js:11:41) at Object.module.exports [as MESSAGE_CREATE] (/root/game-server-watcher/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32) at WebSocketManager.handlePacket (/root/game-server-watcher/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31) at WebSocketShard.onPacket (/root/game-server-watcher/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22) at WebSocketShard.onMessage (/root/game-server-watcher/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10) at WebSocket.onMessage (/root/game-server-watcher/node_modules/ws/lib/event-target.js:132:16) at WebSocket.emit (events.js:314:20) at Receiver.receiverOnMessage (/root/game-server-watcher/node_modules/ws/lib/websocket.js:1068:20) at Receiver.emit (events.js:314:20) at Receiver.dataMessage (/root/game-server-watcher/node_modules/ws/lib/receiver.js:517:14) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! game-server-watcher@1.0.0 start: `node ./dist/server.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the game-server-watcher@1.0.0 start script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2022-10-16T21_08_27_258Z-debug.log **npm log:** 0 info it worked if it ends with ok 1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ] 2 info using npm@6.14.10 3 info using node@v12.20.1 4 verbose run-script [ 'prestart', 'start', 'poststart' ] 5 info lifecycle game-server-watcher@1.0.0~prestart: game-server-watcher@1.0.0 6 info lifecycle game-server-watcher@1.0.0~start: game-server-watcher@1.0.0 7 verbose lifecycle game-server-watcher@1.0.0~start: unsafe-perm in lifecycle true 8 verbose lifecycle game-server-watcher@1.0.0~start: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/root/game-server-watcher/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin 9 verbose lifecycle game-server-watcher@1.0.0~start: CWD: /root/game-server-watcher 10 silly lifecycle game-server-watcher@1.0.0~start: Args: [ '-c', 'node ./dist/server.js' ] 11 silly lifecycle game-server-watcher@1.0.0~start: Returned: code: 1 signal: null 12 info lifecycle game-server-watcher@1.0.0~start: Failed to exec start script 13 verbose stack Error: game-server-watcher@1.0.0 start: `node ./dist/server.js` 13 verbose stack Exit status 1 13 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16) 13 verbose stack at EventEmitter.emit (events.js:314:20) 13 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14) 13 verbose stack at ChildProcess.emit (events.js:314:20) 13 verbose stack at maybeClose (internal/child_process.js:1022:16) 13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5) 14 verbose pkgid game-server-watcher@1.0.0 15 verbose cwd /root/game-server-watcher 16 verbose Linux 5.4.0-126-generic 17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "start" 18 verbose node v12.20.1 19 verbose npm v6.14.10 20 error code ELIFECYCLE 21 error errno 1 22 error game-server-watcher@1.0.0 start: `node ./dist/server.js` 22 error Exit status 1 23 error Failed at the game-server-watcher@1.0.0 start script. 23 error This is probably not a problem with npm. There is likely additional logging output above. 24 verbose exit [ 1, true ] Tried to run it with node v12.20.1 - npm v8.19.2
Author
Owner

@a-sync commented on GitHub (Oct 17, 2022):

looks like the same issue.
i will try to reproduce it by watching the same server, but im fairly sure the error has something to do with the discord server / channel itself.

for now: i would suggest to run the service through pm2, and just let it restart the service whenever it crashes. there is no harm in that, it will pick up where it left.

in the future: i will have some spare time next month, and be able to finish the upgrade to the latest discord.js version (14), that should fix the issue

if my own testing produces any usable outcome i will push a hotfix for this, but have little hope on that since API errors should all be catched already, to not crash the service :-/

@a-sync commented on GitHub (Oct 17, 2022): looks like the same issue. i will try to reproduce it by watching the same server, but im fairly sure the error has something to do with the discord server / channel itself. for now: i would suggest to run the service through pm2, and just let it restart the service whenever it crashes. there is no harm in that, it will pick up where it left. in the future: i will have some spare time next month, and be able to finish the upgrade to the latest discord.js version (14), that should fix the issue if my own testing produces any usable outcome i will push a hotfix for this, but have little hope on that since API errors should all be catched already, to not crash the service :-/
Author
Owner

@a-sync commented on GitHub (Oct 17, 2022):

@Cyclops789 if you're willing to give this another try i created a branch with additional debug messages here: https://github.com/a-sync/game-server-watcher/tree/debug/cyclops

please run this version until it crashes and then copy the end of the output. it should tell us which specific part is causing the crash and maybe enable a workaround.

@a-sync commented on GitHub (Oct 17, 2022): @Cyclops789 if you're willing to give this another try i created a branch with additional debug messages here: https://github.com/a-sync/game-server-watcher/tree/debug/cyclops please run this version until it crashes and then copy the end of the output. it should tell us which specific part is causing the crash and maybe enable a workaround.
Author
Owner

@HamzaJarane commented on GitHub (Oct 17, 2022):

@a-sync sure thanks 👍, btw is there any way to import servers data through this branch? the dash has an export feature but not an import, sorry for asking but I'm running 9 servers and it's kinda hard to add them all again

@HamzaJarane commented on GitHub (Oct 17, 2022): @a-sync sure thanks 👍, btw is there any way to import servers data through this branch? the dash has an export feature but not an import, sorry for asking but I'm running 9 servers and it's kinda hard to add them all again
Author
Owner

@a-sync commented on GitHub (Oct 17, 2022):

just paste the exported config into ./data/default.config.json
but you can also just copy the contents of the ./data/ folder, to keep all
records / configs!

import button on the todo list. (only per server for now sadly :F )

On Mon, Oct 17, 2022 at 1:20 PM Cyclops789 @.***> wrote:

@a-sync https://github.com/a-sync sure thanks 👍, btw is there any way
to import servers data through this branch? the dash has an export feature
but not an import, sorry for asking but I'm running 9 servers and it's
kinda hard to add them all again


Reply to this email directly, view it on GitHub
https://github.com/a-sync/game-server-watcher/issues/4#issuecomment-1280702753,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ADMGZPRN3UXMH4U6CGTGBMLWDUZBRANCNFSM6AAAAAARFSHLKU
.
You are receiving this because you were mentioned.Message ID:
@.***>

@a-sync commented on GitHub (Oct 17, 2022): just paste the exported config into ./data/default.config.json but you can also just copy the contents of the ./data/ folder, to keep all records / configs! import button on the todo list. (only per server for now sadly :F ) On Mon, Oct 17, 2022 at 1:20 PM Cyclops789 ***@***.***> wrote: > @a-sync <https://github.com/a-sync> sure thanks 👍, btw is there any way > to import servers data through this branch? the dash has an export feature > but not an import, sorry for asking but I'm running 9 servers and it's > kinda hard to add them all again > > — > Reply to this email directly, view it on GitHub > <https://github.com/a-sync/game-server-watcher/issues/4#issuecomment-1280702753>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/ADMGZPRN3UXMH4U6CGTGBMLWDUZBRANCNFSM6AAAAAARFSHLKU> > . > You are receiving this because you were mentioned.Message ID: > ***@***.***> >
Author
Owner

@HamzaJarane commented on GitHub (Oct 17, 2022):

sure, thank you!
the bot started to post some logs:
!!! try channel 1016417422594551808
!!! get message
!!! update message
!!! edit message
!!! edited
!!! updated
!!! edited
!!! updated
!!! edited
!!! updated
!!! edited
!!! updated
!!! edited
!!! updated
!!! edited
!!! updated
!!! edited
!!! updated
!!! edited
!!! updated
!!! edited
!!! updated

@HamzaJarane commented on GitHub (Oct 17, 2022): sure, thank you! the bot started to post some logs: !!! try channel 1016417422594551808 !!! get message !!! update message !!! edit message !!! edited !!! updated !!! edited !!! updated !!! edited !!! updated !!! edited !!! updated !!! edited !!! updated !!! edited !!! updated !!! edited !!! updated !!! edited !!! updated !!! edited !!! updated
Author
Owner

@a-sync commented on GitHub (Feb 20, 2023):

updated the app to the latest discord.js give it a try, i am closing this. #5

@a-sync commented on GitHub (Feb 20, 2023): updated the app to the latest discord.js give it a try, i am closing this. #5
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/game-server-watcher#7