I was wondering if you guys could give me some feedback on my Discord - Roblox bot. The bot is connected to each other. If you don’t know what I mean I am trying to explain that the bot is connected from discord to roblox using the API. My bot sends Roblox Group Shouts to Discord in an Embed and it also deletes Group Wall posts that contain the blacklisted words that are in the Javascript file.
This code has a memory leak: Every time the bot state changes to ‘ready’ (even after disconnecting and connecting again normally), it will reinitialize your long polling, thus increasing the chance of rate limiting and decreasing efficiency overall. Consider changing bot.on to bot.once.
Consider pressing Ctrl + Shift + F to automatically format your code.
Add schema verification or error handling to all of your API requests, otherwise an internal server error or improper response from a remote server may cause your process to exit. If you are too lazy for this, consider using a daemon that automatically restarts the program.
This is not feasible for a production environment as Roblox will start rate limiting your requests at some point (depending on polling delay, it will take longer or shorter for Roblox to start rate limiting your IP Address). Consider increasing the polling time inside the noblox.js module or using proxies if you need quick embeds.
Consider removing “Username Logged In”, it serves little to no purpose in a production environment.
Also, I don’t think I need to import the Cookie and GroupID from the config file because it already knows where it is by just doing
const config = require(’./config.json’)
What @Watercoolings was saying is that instead of defining the config var and them needing to do config.someProperty you can just directly get someProperty from the config file. This is called object destructuring.
Memory leaks are a serious issue. If you don’t address it ASAP and figure out how to avoid them, your finishing code will turn out very costly in terms of resources (VPS prices potentially).
In simple terms, a memory leak occurs when your code keeps increasing ram usage without letting go of the ram that is no longer in use or redundant. After a while, this ram usage exceeds the allocated amount for node, or even the system, and then can cause other programs (or itself) to crash. Process monitors like nodemon and PM2 will also stop working if a memory leak occurs; your application will go down after running for a couple hours and nothing will restart it.
A memory leak is the gradual deterioration of system performance that occurs over time as the result of the fragmentation of a computer’s RAM due to poorly designed or programmed applications that fail to free up memory segments when they are no longer needed. Garbage collection is the even stranger term given to the automated process, found in some systems and languages, whereby memory space no longer needed by current applications is consolidated and freed up for reuse. Russell Kay, computerworld.com
Hello, The memory leaks that you mentioned started taking a hit on my Bot. Do you have any suggestions on how to fix that? Like how would I apply the polling times? Thanks!