Bot responds 4 times #9564
Replies: 4 comments 1 reply
-
it seems like you either have multiple instances or nested event listeners, can you show how you have your messageCreate event listener |
Beta Was this translation helpful? Give feedback.
-
it is not nested, it is on the outer most level, this happens at times and then stops happening and it randomly occurs again |
Beta Was this translation helpful? Give feedback.
-
client.on('messageCreate', (message) => {
if (message.author.bot) return;
console.log("message received!");
const joe = message.content.toLowerCase();
if (joe.startsWith(`what`, 0) || joe.startsWith('which', 0) || joe.startsWith('how', 0) || joe.startsWith('why', 0) || joe.startsWith('where', 0)) {
const responses = ["I don't know!", "Use /chat to get your answer", "I'm not sure!", "Why not?", "Because why not?", "I don't care", "Find it out on your own", "No", "Nothing", "Anything can be the answer!"]
const response = responses[Math.floor(Math.random() * 10)]; // I put it in a different variable because you were calculating 2 times which was resulting in 2 different answers (BTW this is not the answer of your question, I just made the code simpler, easy and logical);
console.log(response);
message.reply(response);
};
}); The above code is not the answer to your question but the code was a bit wrong. Now the answer to your question is that the bot was connected 4 times at the same time (in short multiple instances), so the normal solution is to stop all the projects where the bot is logged in or the ultimate solution is Reset the Bot Token so that it will disconnect all the connections and now use the new token to login and it should reply the message only once. |
Beta Was this translation helpful? Give feedback.
-
Thank you it works now! |
Beta Was this translation helpful? Give feedback.
-
So whenever the condition is satisfied, the bot replies 4 times
How can I fix this?
Beta Was this translation helpful? Give feedback.
All reactions