Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

452
Vistas
setInterval() cannot be accessed or cleared after executing command discord.js

I'm trying to make an automemes command, and I can get the interval starting and working properly, but when I try to stop it, the commands gets executed again, starts a new interval and disables it instantly. I can't figure out how can I stop the interval. What can I do? code:

const { SlashCommandBuilder } = require("@discordjs/builders");
const fetch = (...args) => import("node-fetch").then(({default: fetch}) => fetch(...args));

module.exports = {
    data: new SlashCommandBuilder()
    .setName("automemes")
    .setDescription("Sends random memes every 5 minutes (from r/memes)")
    .addBooleanOption(option =>
        option.setName("enabled")
        .setDescription("Set the automemes to on/off")
        .setRequired(true)),

    async execute(client, interaction, Discord) {

        let isEnabled = interaction.options.get("enabled").value;

        async function sendMemes() {

                fetch("https://meme-api.herokuapp.com/gimme/memes")
                .then(res => res.json())
                .then(async json => {
                    
                    const Embed = new Discord.MessageEmbed()
                    .setTitle(json.title)
                    .setImage(json.url)
        
                    if (Embed.title.length > 256) return;

                    await interaction.channel.send({embeds: [Embed]});
                });
        }

        let interval = setInterval(() => sendMemes(), 10000)
        
        async function startInterval () { 
            interval;
            interaction.reply("Automemes enabled! " + ENV.CATKISS);
        }

        async function disableInterval() {

            clearInterval(interval);
            interaction.reply("Automemes disabled! " + ENV.CATKISS);
        }

        isEnabled? startInterval() : disableInterval();
    }
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda