From c3232f82671cdefa543f75596cdb8bb4add6cbc7 Mon Sep 17 00:00:00 2001 From: SowinskiBraeden Date: Tue, 23 Apr 2024 09:20:44 -0700 Subject: [PATCH] fix/admin money command --- commands/admin.js | 11 +++++++---- package.json | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/commands/admin.js b/commands/admin.js index b20150d..98dfa54 100644 --- a/commands/admin.js +++ b/commands/admin.js @@ -318,16 +318,19 @@ module.exports = { if (!success) return client.sendInternalError(interaction, 'Failed to add bank'); } - let newBalance = args[0].options[0].name == 'add' - ? banking.guilds[GuildDB.serverID].balance + args[0].options[0].value - : banking.guilds[GuildDB.serverID].balance - args[0].options[0].value; + if (!client.exists(banking.guilds[GuildDB.serverID].balance)) banking.guilds[GuildDB.serverID].balance = GuildDB.startingBalance; + + const add = args[0].options[0].name == 'add'; + let newBalance = add + ? banking.guilds[GuildDB.serverID].balance + args[0].options[0].options[0].value + : banking.guilds[GuildDB.serverID].balance - args[0].options[0].options[0].value; client.dbo.collection("users").updateOne({"user.userID":targetUserID},{$set:{[`user.guilds.${GuildDB.serverID}.balance`]:newBalance}}, (err, res) => { if (err) return client.sendInternalError(interaction, err); }); const successEmbed = new EmbedBuilder() - .setDescription(`Successfully ${args[0].options[0].name == 'add' ? 'added' : 'removed'} **$${args[0].options[0].value.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}** ${args[0].name == 'add-money' ? 'to' : 'from'} <@${targetUserID}>'s balance`) + .setDescription(`Successfully ${add ? 'added' : 'removed'} **$${args[0].options[0].options[0].value.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2})}** ${add ? 'to' : 'from'} <@${targetUserID}>'s balance`) .setColor(client.config.Colors.Green); return interaction.send({ embeds: [successEmbed] }); diff --git a/package.json b/package.json index e47c222..ebc7f61 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dayzr-bot", - "version": "13.0.5", + "version": "13.0.6", "description": "A General Purpose Discord Bot for DayZ Nitrado Servers.", "main": "index.js", "nodemonConfig": {