I have this code running on a Discord bot. It serves as an alerts system for an online game, where it queries an API every so often and appropriately parses a string and sends it to a guild if it matches certain conditions. Though I don't see any problems with it, I have a feeling it could be optimized or trimmed down. Feel free to visit the http://pso2.kaze.rip/eq/ url to see context for the response.client is a Discord.js client object, and fs is a Promisified version of the standard module.It's supposed to query the URL and parse the data it receives. First, it checks if the first element in the response is different to the one that's cached. If it is, it filters what guilds have the alerts system enabled, and what ships they want to be alerted for. (For example: I have a guild that is enabled for ships 3 and 8, so I'll only receive the objects contained in the eqs array where ship is either 3 or 8)After that's done, it just builds the formatted message and sends it to the guild and updates the cache once every guild has received their alert.setInterval(async () => {    const response = await fetch('http://pso2.kaze.rip/eq/');    if (response.status !== 200) return;    const data = await response.json();    const cache = JSON.parse(await fs.readFile(./cache.json));    if (data[0][time] !== cache[time]) {        const guilds = await client.guilds.filter(guild => { return client.provider.get(guild, alerts) });        for (let guild of guilds) {            let settings = await client.provider.get(guild[1], alerts);            let eqs = data[0][eqs].filter(item => { return settings[ships].includes(item[ship]) });            let format = [];            if (eqs.length <= 0) return;            if (eqs.length !== 10) {                for (let eq of eqs) {                    format.push(`\`SHIP ${eq['ship']}:\` ${eq['name']} (${eq['jpName']})`);                }            }            else {                format.push(`\`ALL SHIPS:\` ${eq['name']} (${eq['jpName']})`);            }            let time = moment(data[0][when]);            let string = `:watch:**IN 40 MINUTES:** (${time.format(HH:mm)} JST)\n${format.join('\n')}`;            await client.channels.get(settings['channel']).send(string);        }        await fs.writeFile(./cache.json, `{ time : ${data[0][time]} }`);    }}, 50000, client);
Alerts system for Discord guilds using Discord.js
javascript