I'm working on a discord bot using discord.js, and I have a bot.on
arrow function that contains a keyv.get
arrow function within it. I want to use return;
to return out of both functions, but I can't get that to work.
Just using the normal return;
at the end just causes it to continue through with the command.
bot.on('message', message=> {
let args = message.content.substring(prefix.length).split(" ");
switch(args[0]) {
case 'startgame':
if (!args[1]) {
message.channel.send('You did not specify a player for the game!');
return;
}
const startingamount = args[2];
user1 = message.mentions.users.first();
user2 = message.author;
if (typeof startingamount == "undefined") {
message.channel.send("You did not specify an amount to bet!");
return;
}
keyv.get(user1.id).then(next => {
console.log(`next is ${next}`);
if (next <= startingamount) {
console.log("Your opponent does not have enough money to start the game!");
// I want to end the function here
return;
// This function stops
}
// Other Function continues here
})
})
Then, I tried to do something like what's below, which also didn't work.
bot.on('message', message=> {
let args = message.content.substring(prefix.length).split(" ");
switch(args[0]) {
case 'startgame':
if (!args[1]) {
message.channel.send('You did not specify a player for the game!');
return;
}
returnvar = 0;
const startingamount = args[2];
user1 = message.mentions.users.first();
user2 = message.author;
if (typeof startingamount == "undefined") {
message.channel.send("You did not specify an amount to bet!");
return;
}
keyv.get(user1.id, 'user').then(next => {
console.log(`next is ${next}`);
if (next <= startingamount) {
return console.log("Your opponent does not have enough money to start the game!");
// want to return out of both functions here
returnvar = 1;
return;
}
})
if (returnvar == 1) {
return;
// should return out of both functions
}
Now, I thought that would work but it doesn't because for some reason returnvar
still equals 0, so the if statement doesn't work.