const Discord = require('discord.js') module.exports = { name:'blackjack', description:'starts a game of blackjack with the user', execute(message, args){ var a = 11; let cardList = [2, 3, 4, 5, 6, 7, 8, 9, 10, a] let botCardList = [a, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1] let card1 = Math.floor(Math.random() * cardList.length) let card2 = Math.floor(Math.random() * cardList.length) let botCard1 = Math.floor(Math.random() * botCardList.length) let botCard2 = Math.floor(Math.random() * botCardList.length) let cardTotal = card1 + card2; let botTotal = botCard1 + botCard2; let cardTotalHit = cardTotal + card1; let botTotalHit = cardTotal + botCard1; let blackJackEmbed = new Discord.MessageEmbed() .setTitle('šŸƒ Blackjack šŸƒ') .setColor('RANDOM') .setDescription('You drew ' + card1 + ' and ' + card2 + ' with a total of ' + cardTotal + '\n\n āœ… - Hit \nāŒ - Stand') .setTimestamp() message.channel.send(blackJackEmbed).then(async message => { for(const e of ["āœ…", "āŒ"]) await message.react(e); //This reacts on the message in the correct order. var validEmojis = ["āœ…", "āŒ"]; //This puts it into an easy array to fetch later. const filter = (reaction, user) => {return (validEmojis.includes(reaction.emoji) && !user.bot && user.id == message.author.id);}; //You can add more parameters here, this just checks it is a valid emoji and the user who reacted isn't a bot, you may want it to ensure that it is the same author however. message.awaitReactions(filter, {max: 1, time: 15000, errors: ["time"]}).then(async collected => { //This is the reaction collector getting the filter, the max is 1 and you need to fill in the max time allowed. message.clearReactions() //Clears all the reactions after it was got. if(collected.first().emoji === 'āœ…'){ let hitBlackJackLoss = new Discord.MessageEmbed() .setTitle('šŸƒ Blackjack šŸƒ') .setColor('RANDOM') .setDescription('You hit and your new card total is ' + cardTotalHit + ', you bust!') .setTimestamp() if(cardTotalHit > 21){ message.edit(hitBlackJackLoss); } let hitBlackJackWin = new Discord.MessageEmbed() .setTitle('šŸƒ Blackjack šŸƒ') .setColor('RANDOM') .setDescription('You hit and your new card total is ' + cardTotalHit + ', you win!') .setTimestamp() if(cardTotalHit == 21 && botTotalHit < 21){ message.edit(hitBlackJackWin); } let hitBlackJackTie = new Discord.MessageEmbed() .setTitle('šŸƒ Blackjack šŸƒ') .setColor('RANDOM') .setDescription('You hit and your new card total is ' + cardTotalHit + ', my total was ' + botTotalHit + `, it's a tie!`) .setTimestamp() if(cardTotalHit == botTotalHit){ message.edit(hitBlackJackTie); } } else if(collected.first().emoji === 'āŒ'){ let standBlackjackLoss = new Discord.MessageEmbed() .setTitle('šŸƒ Blackjack šŸƒ') .setColor('RANDOM') .setDescription('You stand and your card total is ' + cardTotal + ', my total was ' + botTotal + ', I win!') .setTimestamp() if(cardTotal < 21 && botTotal > cardTotal && botTotal <= 21){ message.edit(standBlackjackLoss); } let standBlackjackTie = new Discord.MessageEmbed() .setTitle('šŸƒ Blackjack šŸƒ') .setColor('RANDOM') .setDescription('You stand and your card total is ' + cardTotal + ', my total was ' + botTotal + `, it's a tie!`) .setTimestamp() if(cardTotal == botTotal){ message.edit(standBlackjackTie); } let standBlackjackWin = new Discord.MessageEmbed() .setTitle('šŸƒ Blackjack šŸƒ') .setColor('RANDOM') .setDescription('You stand and your card total is ' + cardTotal + ', my total was ' + botTotal + `, you win!`) .setTimestamp() if(cardTotal <= 21 && botTotal < cardTotal){ message.edit(standBlackjackWin); } } else { console.log("Error- no valid emoji found somehow"); //This should never run, if it allw works. } }); }).catch(err => console.error(err)); } }