const Discord = require('discord.js') module.exports = { name:'blackjack', description:'plays 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 hitBlackJackLoss = new Discord.MessageEmbed() .setTitle('šŸƒ Blackjack šŸƒ') .setColor('RANDOM') .setDescription('You hit and your new card total is ' + cardTotalHit + ', you bust!') .setTimestamp() let hitBlackJackWin = new Discord.MessageEmbed() .setTitle('šŸƒ Blackjack šŸƒ') .setColor('RANDOM') .setDescription('You hit and your new card total is ' + cardTotalHit + ', you win!') .setTimestamp() 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() 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() 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() 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() 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 => { await message.react('ā˜‘').then(r => { const hitFilter = (reaction, user) => reaction.emoji.name === 'ā˜‘' && user.id !== message.author.id; const hit = message.createReactionCollector(hitFilter); hit.on('collect', (r, user) => { if(cardTotalHit > 21){ message.edit(hitBlackJackLoss).then(message.reactions.removeAll()); } if(cardTotalHit == 21 && botTotalHit < 21){ message.edit(hitBlackJackWin).then(message.reactions.removeAll()); } if(cardTotalHit == botTotalHit){ message.edit(hitBlackJackTie).then(message.reactions.removeAll()); } }); }); await message.react('āŒ').then(r => { const standFilter = (reaction, user) => reaction.emoji.name === 'āŒ' && user.id !== message.author.id; const stand = message.createReactionCollector(standFilter); stand.on('collect', (r, user) => { if(cardTotal < 21 && botTotal > cardTotal && botTotal <= 21){ message.edit(standBlackjackLoss).then(message.reactions.removeAll()); } if(cardTotal == botTotal){ message.edit(standBlackjackTie).then(message.reactions.removeAll()); } if(cardTotal <= 21 && botTotal < cardTotal){ message.edit(standBlackjackWin).then(message.reactions.removeAll()); } }); }); }) } }