#Bot send multiple message unpredictably

1 messages · Page 1 of 1 (latest)

inner axle

I'm using discord.js v14.11.0, node v16.20.0, typescript v5.0.4 and forever v3.0.4. I saw there is a question post about sending multiple messages but mine is different.

My problem is my bot will send multiple messages to a guild's channel even though I only call it to send once. This happens very randomly and unpredictably. I'm using forever to let the bot run for more than a week. During that time, the send message API has been called about 10 times. Eight times it sends one message correctly. But two other times it sends two, or three messages. I already handle all 'uncaughtException', 'unhandledRejection' and 'Events.Error' of the discord bot client but no error shows up when these happen. Here is some code example:
https://gist.github.com/ShenKSPZ/7fcfd3dd9c4203bad7e29dea823ee5a5

And I even have a function that sends a message to a channel and then sends a dm msg to a user. Many times, the bot will do things correctly. But sometimes, the bot will send two or more exactly the same messages to the channel and only one to the user. There is no loop in this function and this function has been only called once. I'm already using log to make sure of that.

I've already tried the following stuff to solve this problem but it doesn't help:
Generate a new discord bot token.
Reboot the server to make sure only one instance is running.
Kick the bot and reinvite them into the server.