不和谐机器人不';t循环(Javascript)

不和谐机器人不';t循环(Javascript),javascript,loops,bots,discord,Javascript,Loops,Bots,Discord,我想循环用户,直到他/她猜到,但是,它确实会因为Windows PowerShell上的内存不足而崩溃。我知道原因是因为它确实做了一个无限循环。我不是Javascript方面的专家,我只是在摆弄它 bot.on('message', msg => { if (msg.content === "Vamos a jugar al ahorcado") { const channel = msg.guild.channels.find(channel => chan

我想循环用户,直到他/她猜到,但是,它确实会因为Windows 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;*/
        }

    }
});
bot.on('message',msg=>{
如果(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=[“蚊子”、“卡朱埃拉”、“塔姆伯斯”、“罗通达”、“埃斯帕拉拉波”、“扎尔普利多”、“佩里西奥斯”、“特兰斯托诺”、“威尼斯人”、“肺炎微镜矽肺孢子虫病”、“阿帕卡”、“不可想象的”、“萨彭科”、“马波雷罗”、“德萨罗拉多雷斯”、“阿古亚”、“阿拉伯卡斯库埃拉斯”、“朱古顿”、“祖尔西尔”、“阿森索”、“索罗加多”、“犰狳”、“电子家居”,“电性耳鸣”、“卵巢切除术”、“易用性耳鸣”、“并行性耳鸣”、“delicuescencia”、“耳鼻喉炎”、“发声”、“provocar”、“desvertise”、“esparatrapo”、“抗组胺药”、“cronometro”、“研究所”、“Indiosinacria”、“ventrilocuo”、“tejemaneje”、“anaranjada”、“sanguijuela”、“Roronear”、“sacacorchos”德沙罗、克哈塞雷斯、帕佩莱里亚、汉堡、阿布拉塔斯、卡塞廷、埃斯卡拉巴乔、赫尔马诺、雷莫拉卡、埃斯卡莱拉、奥弗塔、洛罗、索布里诺、番茄、阿莱塔斯、埃斯波萨、马约内萨、雷皮萨、卡尔松西洛、阿马里洛、杜拉兹诺、比贝隆、拉巴诺、埃斯佩乔、三明治、科里弗洛、火箭-0、塔尔科夫、佩卢克利亚”卡内代尔群岛、奥弗塔群岛、巴苏雷罗群岛];
var userGuess=新布尔值(false);
var index=Math.floor(Math.random()*words.length);
var gustedsofar=“``”;
var userInput=“”;
var n=新布尔值(false);
var indexNumber=0;
var计数器=1;
msg.reply('vamosa jugar al-ahorcado!一个安静的adivina esta?描述一个持续的过程!');
单词猜测=单词[索引];
对于(i=0;i{
if(collected.first().content==“cancel”){
返回消息。回复(“取消!”);
};
userInput=collected.first().content;
msg.channel.send(“Dejame ver si'”+userInput+“'esta en la palabra…”);
n=wordGuess.includes(用户输入);
userGuess=false;
if(n==true&&userInput!=wordGuess){
msg.channel.send(“YIKES lo tienes”);
indexNumber=wordGuess.indexOf(用户输入);
guessedSoFar=guessedSoFar.replaceAt((indexNumber+3),(“”+userInput+“”);
}else if(userInput==wordGuess){
返回msg.reply(“Haz ganado!!!La palabara era”+wordGuess);
}否则{
msg.channel.send(“NOPE”);
userGuess=true;
}
});
/*如果我在这里插入以下行,它不会崩溃,只执行一个循环(我不打算这样做,我希望在用户取消或正确猜测之前执行一个循环)。
userGuess=true*/
}
}
});

旁注:我认为不应该使用:new Boolean(false)返回对象。请改用值false。参考:在带有承诺的情况下,您不能使用
。您应该有一个类似
requestGuess()
的函数,如果用户猜错了,将再次调用该函数。