I'm trying to make a discord bot and my client wants me to have a mand that spams something into a text channel.
I have tried using a for loop on its own and a while loop with a for loop as seen below:
With for and while loop:
case "mand":
for(var i = 0; i >=20; i++){
while(i <20){
message.channel.send("spam");
}
}
break;
With for loop:
case "mand":
for(var i = 0; i >=20; i++){
message.channel.send("spam");
}
break;
When I place a message.channel.send outside of the loop, then it shows up once.
Any help would be greatly appreciated, thanks.
I'm trying to make a discord bot and my client wants me to have a mand that spams something into a text channel.
I have tried using a for loop on its own and a while loop with a for loop as seen below:
With for and while loop:
case "mand":
for(var i = 0; i >=20; i++){
while(i <20){
message.channel.send("spam");
}
}
break;
With for loop:
case "mand":
for(var i = 0; i >=20; i++){
message.channel.send("spam");
}
break;
When I place a message.channel.send outside of the loop, then it shows up once.
Any help would be greatly appreciated, thanks.
Share Improve this question edited Dec 2, 2017 at 11:20 André Dion 21.8k7 gold badges58 silver badges60 bronze badges asked Dec 2, 2017 at 11:06 Ryan SRyan S 1292 gold badges4 silver badges10 bronze badges1 Answer
Reset to default 4Neither loop will execute because i
starts at 0
and your loop condition states i >= 20; i++
...
Fix your logic so that it makes sense:
case "mand":
for (var i = 0; i < 20; i++) {
message.channel.send("spam");
}
break;