Bot send multiple message unpredictably

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.
Gist
Send welcome message to new members.
Send welcome message to new members. . GitHub Gist: instantly share code, notes, and snippets.
6 Replies
d.js toolkit
d.js toolkit15mo 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!
ShompiFlen
ShompiFlen15mo ago
is this all the code you have? is the welcome message the one that is triggering multiple times at once?
Lawrence
LawrenceOP15mo ago
I simplified my code to only keep the welcome message part because it shows the problem very clearly. The welcome message is one of the messages which trigger multiple times at once. In my case, all the send message to a channel will randomly trigger multiple times or just once. For the most part, when I tried to test it, they were able to send just one message normally. But after I let it run for more than a few hours with 'forever', it started sending multiple messages at random.
MD
MD15mo ago
i have exactly the same problem https://discord.com/channels/222078108977594368/1137513755840872449 We found the reason, but nobody can find proper solution. Add this listener in your code, and check if retries value is greater than 0
<Client>.rest.on(RESTEvents.Response, console.dir);
<Client>.rest.on(RESTEvents.Response, console.dir);
I kinda fixed it by setting rest retries value to 0 in client settings
rest: {
timeout: 30_000,
retries: 0,
},
rest: {
timeout: 30_000,
retries: 0,
},
but if something will go wrong, bot will not post message at all, so it should be considered only as temporary solution
Lawrence
LawrenceOP15mo ago
Oh! Thanks for that! I will definitely try it and hope it will work for me. Thanks a lot.
一 Arklydh ☕🥯
Hello! I got the same error with my bot... this fix is working?
Want results from more Discord servers?
Add your server