#disable setInterval created in another file of my bot

8 messages · Page 1 of 1 (latest)

blazing cloudBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

fierce ingot
#

node : v16.14.0
discord.js : v14.10.2

#

Here are my two codes in question:
The code setBotStatus.js (located in my ready folder of my handler):

const Discord = require('discord.js');
const BotStatus = require('../../models/BotStatus');

module.exports = async (bot) => {

    const statusData = await BotStatus.findOne();
    if (!statusData) return;

    const { activity, motd, url, status, customInterval } = statusData;

    let currentIndex = 0;

    const updatePresence = async () => {
        const currentMotd = motd[currentIndex];

        if (activity === Discord.ActivityType.Streaming) {
            await bot.user.setPresence({
                activities: [{ name: currentMotd, type: activity, url: url }],
                status: status,
            });
        } else {
            await bot.user.setPresence({
                activities: [{ name: currentMotd, type: activity }],
                status: status,
            });
        }

        currentIndex = (currentIndex + 1) % motd.length;
    };

    if (motd.length > 1) {
        const rotationInterval = customInterval || 30;
        setInterval(updatePresence, rotationInterval * 1000);
    } else {
        const currentMotd = motd[0];

        if (activity === Discord.ActivityType.Streaming) {
            await bot.user.setPresence({
                activities: [{ name: currentMotd, type: activity, url: url }],
                status: status,
            });
        } else {
            await bot.user.setPresence({
                activities: [{ name: currentMotd, type: activity }],
                status: status,
            });
        }
    }
}
old glade
#

Store the return value of that setInterval call somewhere and pass it to clearInterval in your command file when starting the new interval

fierce ingot
old glade
#

Then maybe show how you tried to do it, because the code you showed doesn’t

fierce ingot