0
votes

Right now I have a Discord bot that is in approximately 575 servers, and on the website I made it lists the current server count of the bot. Right now, my method is to log the bot in every 5 minutes on the express app for the webpage and save the current server count to be served to the client. This causes memory usage spikes whenever I have to log in though, and using a whole discord.js application for one function seems inefficient.

I tried using the Discord API endpoint, but that was extremely laggy because there is only an endpoint for listing all the servers, not just the count. The endpoint also can only send info on 100 servers at a time, so I'd have to make a lot of different requests.

I'm hoping that there's a way to do this that would use less memory but still be fast. I tried looking into discord.js's source code to see if I could just isolate the functionality I needed, but I wasn't able to even find where in the code the data is requested from Discord. If anyone is able to figure how I could do this, it would be greatly appreciated.

2
Does this answer your question? stackoverflow.com/questions/51572008/…Jabster28
@Jabster28, no, that's my current method. After asking the question, I switched to logging in every 5 minutes, checking server count, and logging out, but I'd still rather not have to use discord.js at all because of the memory demands it has.Colin Hanes
shouldn't the bot be running 24/7 anyway?Jabster28
@Jabster28 it is, but all of this code is running on an express application for my webpage. The bot is running in a completely different place.Colin Hanes

2 Answers

0
votes

You can try using free online database as a way to "communicate" data between your bot and your express app.

For example, you can use Cloud Firestore. Every 15 minutes (or whatever frequency you want) you can have your bot save server count information (and update time too if you want) into Cloud Firestore. Every time a client loads up your webpage, it'll retrieve the data from Cloud Firestore and be able to display server count and last updated time. (Alternatively you could have your express app retrieve that data every 15 minutes and cache it to send to the client)

You can use this method to share other data from your bot to your express app too.

0
votes

The solution I ended up needing was a Discord websocket connection. That keeps everything updated live without having to deal with the memory and caching issues that come with discord.js. I've had a few other questions after this one on that topic, check those out if you want to see more on Discord websocket connections.