Possible AsyncEventEmitter memory leak detected
Anyone knows why my discord bot throws this errors?
25 Replies
- 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!
it says memory leak but there is no memory leak. i think it mentions that 11 ready and error events are listened but according to my code it never does that. what is going on?
are you perhaps listening (client.on()) inside an event handler like an interactionCreate listener or a command or using nested collectors?
I dont think so

In fact I don't use more than one collector in any file
most collectors I created have very short durations (the longest is around 5 minutes)
I can share all the parts where I use the collectors
Are you using
setInterval
anywhere, such as for a rotating presence?there's only one interval I use and it's not related to the discord bot, it's just an interval that cleans a collection once in a while
what do you mean by rotating presence? I don't understand
to update the bot's presence every once in a while
eg updating number of guilds in presence
yes there is. every hour using cronjob
I only use the number of servers and users from cache
https://github.com/discordplace/discord.place/blob/main/server/src/utils/updateClientActivity.js
make sure you're only starting that after the client logs in
I do so
I run it in ready, guildCreate and guildRemove events. I start the cronjob in the ready event, could this be the problem?
but this errors appeared recently. this script has been like this for months
how are you running the cronjob in guildCreate?
manually?
I only call the updateClientActivity function inside the event
inside the ready event I have a cronjob that runs every hour that calls updateClientActivity with other scripts
https://github.com/discordplace/discord.place/blob/main/server/src/client.js#L160
can you try only having the cronjob? if you want you can set it lower
we think it may cause issues if your bot joins/leaves guilds too quickly
specifically the setPresence listeners may not deattach as quickly as needed, triggering the warning
which should not be an issue since they'll be deattached, but it does generate that warning
actually first can you run the bot with node's --trace-warnings flag?
I am logging them and in the last days there has not even been more than 1 guild added/removed the bot
but here's the thing. this error was not there this morning and this morning, the bot was down for about 6-8 hours due to an problem caused by the hosting. before it was down, it was giving connect timeout errors many times. could there be a bug related to this?
I'll try
actually that might've been the problem if you're running an old djs version
adding a check on the ws status before setPresence should fix it
client.ws.status
to see if it's ready or not, right?
yep
Isn't client.isReady() already doing this?
anyway, I've added --trace-warnings for now and I'll wait
looks like it actually
it also checks if it hasn't been destroyed but it won't for your case
👍 I'll let you know if it happens again
actually we just noticed that since the async event emitter update, that might not work anymore for your warning
but if you add that check it shouldn't happen again, at least not because of this
is this a known bug and fixed in new versions?