I have occurred an error in my Discord Bot. I have received this error in discord.js v11 and v12.
Is there any way to fix this issue?
(node:929) MaxListenersExceededWarning: Possible EventEmitter memory
leak detected. 11 message listeners added to [Client]. Use
emitter.setMaxListeners() to increase limit
I also have tried adding
emitter.setMaxListeners() by itself in the code but didn’t work. Sorry if this sounds completely stupid, I have never occurred this error ever since I coded a discord.js bot until now.
This error also occurs in another coding platform (e.g. Repl.it, etc)
I saw that this is because of CPU usage but I’m not sure how I will be able to run this on my own laptop instead of a coding platform like Glitch.
Any help is appreciated
Can you please share the logic (your code) in your message event method?
I have many (so if there’s an error, I can find which one has it much faster). And which one?
Do you have 11 message event methods by purpose?
Let me check, give me 2 minutes
18 or 19… wow that’s a lot.
Is the solution to add all of the commands into 1 message event?
If you have 18-19 events just for dealing with commands then YES…
i sound so stupid lol. if i occur any errors, i’ll let you know. keep your notifications on please!
Sure, but it is still bad practise to make unnecessary event listeners.
always bad it doubles response time for each listener
Actually no, in time complexity it’s linear
erm, yea, bai, idk what that means
You can think of it like this:
John has to jog 5 km, he uses 10 minutes per kilometer.
So jogging 5 km would take 50 minutes.
Let’s add 1 km to his trip, that would only add 10 more minutes, not double the amount of time it took to run 5 km.
Thank you buddy! It works, that part is removed from the log. Thank you so much! Lol, it’s probably some baby error and you’re probably like, “dude, there’s only 2 steps lol”. WOOHOO
No problem, happy to help