I am trying to create a setup command, where the user enters values which are then saved in an SQL db. However I am having trouble getting the awaitMessages method to wait within a for loop.
let input = []; // declare input as empty array
let setupQ = ['Please enter the role ID of admin', 'Please enter the role ID of mod', 'Please enter the ID of your log channel', 'Please enter the ID of your join/leave channel'];
for (i = 0; i < 4; i++) {
message.channel.send(setupQ[i])
const filter = (user) => {
return user.author.id === message.author.id
};
message.channel.awaitMessages(filter, { max: 1, time: 15000, errors: ['time'] })
.then(async collected => {
input[i] = collected.first().content //takes user input and saves it
}).catch(collected => {
message.channel.send(`:x: Setup cancelled - 0 messages were collected in the time limit, please try again`).then(m => m.delete({ timeout: 4000 }));
});
};
What currently happens, is that the bot immediately outputs the questions, without waiting for a user to reply. I have previously got this command to work, but by using 4 awaitMessages methods which were ugly and slow. (not to mention a formatting nightmare).
Can anyone see what I have to do to make it wait?