I am making a setup command, using the #awaitMessages listener 2 times in a row to set up a server correctly from a user input, but try as I might, I cannot achieve the effect of each message being sent, then collecting data, then sending the next message etc. Here is my code (I have removed lots of clutter you dont need)
message.channel.send("Please enter the role ID of admin:").then(() => {
const filter = m => m.content
message.channel.awaitMessages(filter, { max: 1, time: 10000, errors: ['time'] })
.then(collected => {
message.channel.send(':white_check_mark: Admin role set up correctly')
}).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 }));
})
});
message.delete().then(async () => {
await message.channel.send("Please enter the role ID of moderator:").then(() => {
const filter = m => m.content
message.channel.awaitMessages(filter, { max: 1, time: 10000, errors: ['time'] })
.then(collected => {
message.channel.send(':white_check_mark: Mod role set up correctly')
}).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 happens is the bot does not wait for my collect event, and just moves on to sending the next message e.g.
Please enter the role ID of administrator
Please enter the role ID of moderator
What am I doing wrong? - there is no error thrown (since I have not made a mistake in my code - it just does not do what I need)
Edit:
message.channel.awaitMessages(filter, { max: 1, time: 10000, errors: ['time'] })
.then(collected => {
if (!collected.content === "test") return;
message.channel.send(':white_check_mark: Admin role set up correctly')
}).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 }));
})
message.channel.send("Please enter the role ID of moderator:").then(() => {
const filter = m => m.content
message.channel.awaitMessages(filter, { max: 1, time: 10000, errors: ['time'] })
.then(collected => {
if (!collected.content === "test") return;
message.channel.send(':white_check_mark: Mod role set up correctly')
}).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 }));
})
});
});
message.delete()