n0ur
DIAdiscord.js - Imagine an app
•Created by n0ur on 3/26/2024 in #djs-questions
Building an Efficient Bot: Task Automation and Resource Optimizatione
I would like to create a bot that needs to perform a task job every 5 minutes.
Here's what the task do:
1. Retrieving all the guilds from my database and obtaining the value of the variable: lastMessageDate (MongoDB).
2. Iterating through all the fetched guilds:
- Performing the necessary actions with the lastMessageDate obtained for each guild.
So every 5min the bot will send a request to mongodb and retreive the lastMessageDate for each guild.
When a message is sent, the bot will (With MessageCreated event):
1. Identify the guild to which the message belongs.
2. Search for this guild in my database.
3. Update the value of the variable lastMessageDate for this guild in the database.
(More details: In fact, my bot is a minigame bot with a lot of minigames and cultural question games. Every 5 minutes, I want to retrieve the lastMessageDate to then check if the guild is quite active. If the guild is active, I would like to generate a number, and if the number falls within a certain range, I want to start a minigame for this guild.) Initially, I had thought about doing this directly within the MessageCreated event, but I realized that it might be even more costly to do this every time a message is created, especially if the bot is on a large number of servers and those servers generate a significant amount of messages.
I'd like to know if this will require significant resources. If yes, how can I optimize it to minimize resource usage? or maybe you guys have a better idear of how to do this
6 replies