Possible AsyncEventEmitter memory leak detected

Anyone knows why my discord bot throws this errors?
25 Replies
d.js toolkit
d.js toolkit3d 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!
skyhan
skyhanOP3d ago
No description
skyhan
skyhanOP3d ago
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?
└── [email protected] -> ./node_modules/.pnpm/[email protected]/node_modules/discord.js

node -v
v18.20.4
└── [email protected] -> ./node_modules/.pnpm/[email protected]/node_modules/discord.js

node -v
v18.20.4
Amgelo
Amgelo3d ago
are you perhaps listening (client.on()) inside an event handler like an interactionCreate listener or a command or using nested collectors?
skyhan
skyhanOP3d ago
I dont think so
No description
skyhan
skyhanOP3d ago
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
TÆMBØ
TÆMBØ3d ago
Are you using setInterval anywhere, such as for a rotating presence?
skyhan
skyhanOP3d ago
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
Amgelo
Amgelo3d ago
to update the bot's presence every once in a while eg updating number of guilds in presence
skyhan
skyhanOP3d ago
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
Amgelo
Amgelo3d ago
make sure you're only starting that after the client logs in
skyhan
skyhanOP3d ago
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
Amgelo
Amgelo3d ago
how are you running the cronjob in guildCreate? manually?
skyhan
skyhanOP3d ago
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
Amgelo
Amgelo3d ago
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?
skyhan
skyhanOP3d ago
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
Amgelo
Amgelo3d ago
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
skyhan
skyhanOP3d ago
to see if it's ready or not, right?
Amgelo
Amgelo3d ago
yep
skyhan
skyhanOP3d ago
Isn't client.isReady() already doing this? anyway, I've added --trace-warnings for now and I'll wait
Amgelo
Amgelo3d ago
looks like it actually it also checks if it hasn't been destroyed but it won't for your case
skyhan
skyhanOP3d ago
👍 I'll let you know if it happens again
Amgelo
Amgelo3d ago
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
skyhan
skyhanOP3d ago
is this a known bug and fixed in new versions?

Did you find this page helpful?