Getting 'variable is not defined at client' error
AkonZ

I am trying to access a variable I declared however I am getting undefined. I declared the variable using the 'var' keyword in an if-statement(for a discord bot command) and tried accessing its value in another if-statement but that is not working, anyone could know whats the problem ? A similar example to my problem could be shown here: [NodeJS]
if (command == 'bla'){
var number = 7;
}
if (command == 'vla'){
var newNumber = number + 2;
message.channel.send(newNumber)
}

You are viewing a single comment. View All
AkonZ

@heyitsmarcus Hello Marcus, thank you for your reply. Actually I am full aware of the scopes and I already tried your approach. It didnt work. I would get the value 0 for number and not 7 when using the command 'vla'. The reason is that the bla command is not being fulfilled therefore the variable is not getting updated. I found a temporary fix which is to use the command 'bla' and right after it use the command 'vla' (in the discord server of course) , only then will the value of number be 7 because the if statement for 'bla' got fulfilled. I want to find a way to make the value of number = 7 without having to use the first command before the second command as it would be inconvenient for my discord users. Let me know if you have a fix for the problem!