Я хочу l oop пользователя до тех пор, пока он не угадает, но он делает sh для заголовка памяти в Window PowerShell. Я знаю, что причина в том, что оно действительно бесконечно. Я не эксперт по Javascript, я просто бездельничаю.
bot.on('message', msg => {
if (msg.content === "Vamos a jugar al ahorcado") {
const channel = msg.guild.channels.find(channel => channel.name === "chat-general");
const filter = m => m.author.id === msg.author.id;
var words = ["mosquito","cajuela","tambores", "rotonda", "esparatrapo", "zarpullido", "perjuicios", "transtorno", "veniste", "pneumonoultramicroscopicsilicovolcanoconiosis", "apapachar", "inefable", "sapenco", "mamporrero", "desarrolladores", "aguja", "cascarabias", "jugueton", "zurcir", "ascensor", "sonrojado", "armadillo", "electrodomestico", "electroencefalografista", "ovoviviparo", "transustanciacion", "paralelepipedo", "delicuescencia", "otorrinolaringologo", "vocalizacion", "provocar", "desvertirse", "esparatrapo", "antihistaminico", "cronometro", "institucionalizacion", "indiosincrasia", "ventrilocuo", "tejemaneje", "anaranjada", "sanguijuela", "ronronear", "sacacorchos", "desarrollar", "quehaceres", "papeleria", "hamburguesa", "abrelatas", "calcetines", "escarabajo", "hermano", "remolacha", "escalera", "oferta", "loro", "sobrino", "tomate", "aletas", "esposa", "mayonesa", "repisa", "calzoncillo", "amarillo", "durazno", "biberon", "rabano", "espejo", "sandwich", "coliflor", "rocket-0", "tarkov", "peluqueria", "carnederes", "oferta", "basurero"];
var userGuess = new Boolean(false);
var index = Math.floor(Math.random() * words.length);
var guessedSoFar = "```";
var userInput = "";
var n = new Boolean(false);
var indexNumber = 0;
var counter = 1;
msg.reply('Vamos a jugar al ahorcado! A ver quien adivina esta? Escribe una letra continuacion!');
wordGuess = words[index];
for(i = 0; i < wordGuess.length; i++){
guessedSoFar += "_ ";
}
guessedSoFar += "```";
while(userGuess != true){
msg.channel.send(guessedSoFar);
msg.channel.send("Escribe una letra!");
msg.channel.send(wordGuess);
msg.channel.awaitMessages(filter, {
max: 1,
time: 10000
}).then(collected => {
if(collected.first().content === "cancel"){
return msg.reply("Cancelled!");
};
userInput = collected.first().content;
msg.channel.send("Dejame ver si '" + userInput + "' esta en la palabra...");
n = wordGuess.includes(userInput);
userGuess = false;
if(n == true && userInput != wordGuess){
msg.channel.send("YIKES lo tienes");
indexNumber = wordGuess.indexOf(userInput);
guessedSoFar = guessedSoFar.replaceAt((indexNumber + 3), (" " + userInput + " "));
} else if(userInput == wordGuess){
return msg.reply("Haz ganado!!! La palabara era " + wordGuess);
}else {
msg.channel.send("NOPE");
userGuess = true;
}
});
/*If I insert the following line here it doesn't crash and do just one loop. (I don't intent to do that, I want a loop until user Cancel or Guess Correctly).
userGuess = true;*/
}
}
});
введите описание изображения здесь