Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
Habilitar y deshabilitar el comando en JavaScript discord.js

Estoy tratando de hacer un comando de automemes, puedo hacer que envíe memes automáticamente, pero cuando trato de deshabilitarlo, ¡envía los Automemes disabled! comando, pero todavía los envía. Aquí está el código:

 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; switch (isEnabled) { case true: interaction.reply("Automemes enabled! " + ENV.CATKISS) break; case false: isEnabled = false; break; } 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]}); }); } isEnabled? setInterval(() => sendMemes(), 10000) : interaction.reply("Automemes disabled! " + ENV.CATKISS); } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Veo lo que está tratando de lograr pero, como dijo @Zsolt Meszaros anteriormente, su intervalo nunca se borra. Eso significa que si ese intervalo se activa una vez, continuará perpetuamente hasta que su bot se apague. Intente declarar su intervalo como una constante para que pueda habilitarlo y deshabilitarlo como lo desee.

 const myInterval = setInterval(sendMemes, 10000) //declaring interval async fucntion startInterval() { myInterval; //function to start interval } async function disableInterval() { clearInterval(myInterval); //function to clear interval interaction.reply(interaction.reply("Automemes disabled! " + ENV.CATKISS)); } isEnabled? startInterval() : disableInterval(); //added starter and stopper functions } }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!