const { EmbedBuilder } = require('discord.js'); const { Bank, addBank } = require('../structures/bank'); module.exports = { name: "money", debug: false, description: "add/remove money from user", usage: "[opt.] [user] [amount]", permissions: { channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"], member: ["MANAGE_GUILD"], }, options: [ { name: "add_or_remove", description: "Add or remove money from a user", value: "add_or_remove", type: 3, required: true, choices: [ { name: "add", value: "add" }, { name: "remove", value: "remove" }, ] }, { name: "amount", description: "The amount to add to balance", value: "amount", type: 5, min_value: 0.01, required: true, }, { name: "from", description: "User to alter balance", value: "from", type: 6, required: true, }, ], SlashCommand: { /** * * @param {require("../structures/QuarksBot")} client * @param {import("discord.js").MessageCreate} message * @param {string[]} args * @param {*} param3 */ run: async (client, interaction, args, { GuildDB }) => { if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) { return interaction.send(`You are not allowed to use the bot in this channel.`); } const permissions = bitfieldCalculator.permissions(interaction.member.permissions); let canUseCommand = false; if (permissions.includes("MANAGE_GUILD")) canUseCommand = true; if (client.exists(GuildDB.botAdmin) && interaction.member.roles.includes(GuildDB.botAdmin)) canUseCommand = true; if (!canUseCommand) return interaction.send('You don\'t have the permissions to use this command.'); const targetUserID = args[2].value.replace('<@!', '').replace('>', ''); let banking = await client.dbo.collection("banks").findOne({"account.userID": targetUserID}).then(banking => banking); if (!banking) { banking = { userID: targetUserID, guidls: { [guildID]: { account: { balance: GuildDB.startingBalance, cash: 0.00, } } } } // Register inventory for user let newBank = new Bank(); newBank.createBank(targetUserID, GuildDB.serverID, GuildDB.startingBalance); newBank.save() .catch(err => { if (err) { client.error(err); const embed = new EmbedBuilder() .setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`) .setColor(client.config.Colors.Red) return interaction.send({ embeds: [embed] }); } }); } else banking = banking.banking; if (!client.exists(banking.guilds[GuildDB.serverID])) { const success = addBank(banking.guilds, GuildDB.serverID, targetUserID, client, GuildDB.startingBalance); if (!success) { client.error(err); const embed = new EmbedBuilder() .setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`) .setColor(client.config.Colors.Red) return interaction.send({ embeds: [embed] }); } } const newBalance = args[0] == 'add' ? banking.guilds[GuildDB.serverID].account.balance + args[1].value : banking.guilds[GuildDB.serverID].account.balance - args[1].value; client.dbo.collection("banks").updateOne({"account.userID":targetUserID},{$set:{[`banking.guilds.${GuildDB.serverID}.account.balance`]:newBalance}}, function(err, res) { if (err) { client.error(err); const embed = new EmbedBuilder() .setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nContact the Developers\nhttps://discord.gg/YCXhvy9uZw`) .setColor(client.config.Colors.Red) return interaction.send({ embeds: [embed] }); } }); const successEmbed = new EmbedBuilder() .setDescription(`Successfully ${args[0] == 'add' ? 'added' : 'removed'} $${args[0].options[1].value.toFixed(2)} ${args[0] == 'add' ? 'to' : 'from'} <@${targetUserID}>'s balance`) .setColor('GREEN'); return interaction.send({ embeds: [successEmbed] }); }, }, }