Ask coding questions

← Back to all posts
Why is verifSent not assigned 1?
Axel1672 (5)

client.on('message', (message) => {
var verifSent = 0;
if (message.content.toLowerCase() === Prefix + 'verify' && verifSent == 1) {
message.channel.send("<@" + message.author.id + ">" + " You already have a pending verification");
}
else if (message.content.toLowerCase() === Prefix + 'verify' && verifSent != 1) {
if (message.channel.type === "text") {
if (message.channel.id == 829952301317750804) {
var verificationMessage = "";
var x = 0
while (x < 6) {
verificationMessage += randomChars[Math.floor(Math.random() * randomChars.length)]
x = x + 1
}
console.log(verifSent);
message.author.send("Here is your verification message: " + verificationMessage).then(MessageSent)
.catch(() => {
message.channel.send("<@" + message.author.id + ">" + " I couldn't send you the verification message");
})
function MessageSent() {
message.channel.send("<@" + message.author.id + ">" + " I have sent the verification message to your DMs");
verifSent = 1
}
break;
}
}
client.on('message', (message) => {
if (message.channel.type === "dm") {
if (message.content == verificationMessage) {
message.author.send("Verification complete!");
}
else {
message.author.send("Incorrect please try again");
}
}
})
}
});

Answered by AloegelhiPlaysR (131) [earned 5 cycles]
View Answer
Comments
hotnewtop
AloegelhiPlaysR (131)

You set it to 0 everytime the client sees a message, to prevent this, move the variable outside of the client.on('message'... part.

R2D2VaderBeef (8)

I think its because you set it to 0 every time a message is received.