-3

I'm coding a bot using discord.js. I'm trying to setup a system where the bot is allowed to send a message as long as it is not blacklisted. However, every time I run the function, I get this message: ReferenceError: res is not defined

I've tried moving var res so many times and I can't figure it out. Does anyone know how to arrange this properly?

function getNum() {

    var randNum = [
        "1",
        "2",
        "3",
    ];
    // Blacklist Entries Start
    var blacklistNum = [
        "1"
    ];
    // Blacklist Entries End
    return randNum[Math.floor(Math.random()*randNum.length)];
    return;
}
if(res === blacklistNum) {
    getNum();
}

getNum();
message.channel.send(res);
tpschmidt
  • 2,479
  • 2
  • 17
  • 30
geixco
  • 1

1 Answers1

2

res is only available in your function scope. Either you define it globally or you return it from your function.

tpschmidt
  • 2,479
  • 2
  • 17
  • 30