I want my bot to recognize that if my collection equals to 1 then do something but the bot is not getting if it was 1 here is my code
if(button.id === 'policeticket') {
let member = button.clicker.user.id;
button.channel.send("type a number")
const filter = m => m.author.id == button.clicker.user.id;
button.channel.awaitMessages(filter, { max: 1, time: 60000, errors: ['time'] })
.then(async collection => {
let number = collection.first();
if(number === "1") {
button.channel.send("test")
}
})
}
})
CodePudding user response:
I don't no if is correct, but i think do you are comparate a number with a string, and that's comparate always return false if value was number.
in your case i would try this code.
if (button.id === 'policeticket') {
let member = button.clicker.user.id;
button.channel.send("type a number")
const filter = m => m.author.id == button.clicker.user.id;
button.channel.awaitMessages(filter, { max: 1, time: 60000, errors: ['time'] })
.then(async collection => {
let number = collection.first();
if (number === 1) {
button.channel.send("test")
}
})
}
CodePudding user response:
if (button.id === 'policeticket') {
let member = button.clicker.user.id;
button.channel.send("type a number")
const filter = m => m.author.id == button.clicker.user.id;
button.channel.awaitMessages(filter, { max: 1, time: 60000, errors: ['time'] })
.then(async collection => {
let number = parseInt(collection.first());
if (number === 1) {
button.channel.send("test")
}
})
}