'How to collect multiple message in a loop using awaitMessage?
Im trying to create a game command in which players need to guess where the cat is among a number of boxes. The basic concept was done but I somehow can't collect more than 1 message, it would stop the process after collecting the first one
The code:
const Command = require("../structures/Command.js");
module.exports = new Command({
name: "cat",
async run(message, args, client) {
//Preparing stuff
var i = 0;
var cat = Math.floor(Math.random()*5)+1;
message.channel.send("A wild cat have appeared and hiden in 5 random boxes, can you find it?")
const filter = (user) => {
return user.author.id === message.author.id
};
//Loop
while (i<10) {
console.log(cat);
let collected = await message.channel.awaitMessages(filter, { max: 1, time: 15000, errors: ['time'] });
answer = collected.first().content;
console.log(answer)
//checking
if (answer === cat){
message.reply("You opened the correct box!");
var i = 727;
console.log("Yes")
} else {
var move = Math.floor(Math.random()*10)+1;
if (cat===1){var move = 1} else if (cat===5){var move = 10}
if (move<5){var cat = cat+1} else {var cat = cat-1}
var i = i + 1;
var days = 10 - cat;
console.log(cat)
message.channel.send(`You didn't guessed the correct box, the cat has now moved to another box. You got ${days} tries left`)
}
}
}
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
