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

258
Vistas
Why am I unable to repeatedly send the same message with my discord bot in node.js?

I am trying to code a discord spam bot as a challenge since I am a beginner coder and for use on my friend's private server. Everything works up until I use a either a while or for loop (I tried both). It worked when I only sent the message once but when I put message.channel.send(spamWord) inside a for loop that runs as many times as the user requests it just doesn't send. An issue I was running into was a deprecation warning but I fixed that. I expected that to be the problem but apparently there is another. Maybe my syntax is wrong but when it was wrong in different parts of the code I got an error, this time nothing appears in the console. If I put the message.channel.send(spamWord) after the for loop it executes it like the for loop was never there. Here is my code.

const express = require("express");
const app = express();


app.listen(3000, () => {
    console.log("Project is Running!");
})

app.get("/", (req, res) => {
    res.send("Hello World!");
})

const Discord = require("discord.js");
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] });

client.on("messageCreate", message => {


        //* ----------------Spam Code--------------*/ 

    if (message.content === "Spam") {
    message.channel.send("I will spam the contents of the last message in this channel after 10 seconds. Then after I send a message type a number and that will be how many times that message is spammed.");
    var delayInMilliseconds = 10000; //1 second
    let i = 0

    setTimeout(function() {


        spamWord = message.channel.lastMessage
        message.channel.send("OK, now how many times will I spam it? You have 10 seconds to type you number")
        
        setTimeout(function() {
            let spamNum = message.channel.lastMessage

            for (i in parseInt(spamNum)) {

                message.channel.send(spamWord);

            }
        }, delayInMilliseconds)


    }, delayInMilliseconds);
    }
    
})

client.login(process.env.token);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It looks like because you are looping in the for-in loop using int

for (i in parseInt(spamNum)) {
  message.channel.send(spamWord);
}

Change to this.

for (var i = 0; i < parseInt(spamNum); i++) {
  message.channel.send(spamWord);
}
about 4 years ago · Juan Pablo Isaza Denunciar
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