const { MessageEmbed, MessageActionRow, MessageButton } = require('discord.js'); const mongoose = require("mongoose"); const UserSave = require('../models/UserSchema'); const BlackJackSave = require('../models/BlackJackSchema'); module.exports = { data: { name: 'stand' }, async execute (interaction){ let foundBJ = await BlackJackSave.findOne({ userID: interaction.user.id, guildID: interaction.guild.id }); let UserProfile = await UserSave.findOne({ userID: interaction.user.id, guildID: interaction.guild.id }); if(interaction.message.interaction.user.id !== interaction.user.id) { let Embed3 = new MessageEmbed() .setTitle("You cannot interact with another users game!") .setColor("RED") .setTimestamp() .setFooter("Blackjack") interaction.reply({ embeds: [Embed3] }) return; } else { if(foundBJ) { let EmbedWon = new MessageEmbed() .setTitle("You won!") .setDescription("Your winnings have been sent to your wallet.") .addField("Bet:", `${foundBJ.bet}`) .addField("Your Cards:", `${foundBJ.cards}`) .addField("Total:", `${foundBJ.total}`) .addField("Dealer Cards:", `${foundBJ.dealer}`) .addField("Total:", `${foundBJ.total2}`) .setColor("GREEN") .setTimestamp() let EmbedDraw = new MessageEmbed() .setTitle("It's a draw!") .setDescription("Your money has been returned to your wallet.") .addField("Bet:", `${foundBJ.bet}`) .addField("Your Cards:", `${foundBJ.cards}`) .addField("Total:", `${foundBJ.total}`) .addField("Dealer Cards:", `${foundBJ.dealer}`) .addField("Total:", `${foundBJ.total2}`) .setColor("BLUE") .setTimestamp() let EmbedLoss = new MessageEmbed() .setTitle("You lost!") .setDescription("Your bet has been sent to the server bank.") .addField("Bet:", `${foundBJ.bet}`) .addField("Your Cards:", `${foundBJ.cards}`) .addField("Total:", `${foundBJ.total}`) .addField("Dealer Cards:", `${foundBJ.dealer}`) .addField("Total:", `${foundBJ.total2}`) .setColor("RED") .setTimestamp() if(foundBJ.total > foundBJ.total2) { await UserSave.findOneAndUpdate({ userID: interaction.user.id, guildID: interaction.guild.id }, { wallet: +UserProfile.wallet + +foundBJ.bet }); await interaction.reply({ embeds: [EmbedWon] }); return; } else if(foundBJ.total === foundBJ.total2) { await interaction.reply({ embeds: [EmbedDraw] }); return; } else if(foundBJ.total < foundBJ.total2) { await UserSave.findOneAndUpdate({ userID: interaction.user.id, guildID: interaction.guild.id }, { wallet: +UserProfile.wallet - +foundBJ.bet }); await interaction.reply({ embeds: [EmbedLoss] }); return; } } else { let Embed2 = new MessageEmbed() .setTitle("Couldn't find a game to stop.") .setColor("RED") .setTimestamp() .setFooter("Blackjack") interaction.reply({ embeds: [Embed2], ephemeral: true }); } } } }