fix withdraw/deposit commands
This commit is contained in:
4 files changed
+200
-5
No files matched your search
@@ -0,0 +1,98 @@
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: "withdraw",
|
||||
description: "withdraw cash from balance",
|
||||
usage: "[amount]",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
SlashCommand: {
|
||||
options: [
|
||||
{
|
||||
name: "amount",
|
||||
description: "amount to withdraw",
|
||||
value: "amount",
|
||||
type: 10,
|
||||
min_value: 0.01,
|
||||
required: true,
|
||||
}
|
||||
],
|
||||
/**
|
||||
*
|
||||
* @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.`);
|
||||
}
|
||||
|
||||
let banking = await client.dbo.collection("banking").findOne({"account.userID": interaction.member.user.id}).then(banking => banking);
|
||||
|
||||
if (!banking) {
|
||||
banking = {
|
||||
account: {
|
||||
userID: interaction.member.user.id,
|
||||
balance: GuildDB.startingBalance,
|
||||
cash: 0.00,
|
||||
}
|
||||
}
|
||||
|
||||
client.dbo.collection("banking").insertOne(banking, function(err, res) {
|
||||
if (err) {
|
||||
client.log(err);
|
||||
let embed = new MessageEmbed()
|
||||
.setTitle(err)
|
||||
.setColor("RED")
|
||||
|
||||
return interaction.send({ embeds: [embed] });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (args[0].value > banking.account.balance) {
|
||||
let embed = new MessageEmbed()
|
||||
.setTitle('Insufficient funds')
|
||||
.setColor("RED");
|
||||
|
||||
return interaction.send({ embeds: [embed] });
|
||||
}
|
||||
|
||||
newBalance = banking.account.balance - args[0].value;
|
||||
newCash = banking.account.cash + args[0].value;
|
||||
|
||||
client.dbo.collection("banking").updateOne({"account.userID":interaction.member.user.id},{$set:{"account.balance":newBalance,"account.cash":newCash}}, function(err, res) {
|
||||
if (err) {
|
||||
client.log(err);
|
||||
let embed = new MessageEmbed()
|
||||
.setTitle(err)
|
||||
.setColor("RED")
|
||||
|
||||
return interaction.send({ embeds: [embed] });
|
||||
}
|
||||
});
|
||||
client.dbo.collection("inventories").updateOne({"inventory.userID":interaction.member.user.id, "inventory.items.type":"wallet"},
|
||||
{$set:{"inventory.items.$.cash":newCash}}, function(err, res) {
|
||||
if (err) {
|
||||
client.log(err);
|
||||
let embed = new MessageEmbed()
|
||||
.setTitle(err)
|
||||
.setColor("RED")
|
||||
|
||||
return interaction.send({ embeds: [embed] });
|
||||
}
|
||||
});
|
||||
|
||||
let successEmbed = new MessageEmbed()
|
||||
.setTitle('Success')
|
||||
.setDescription(`Successfully withdrew $${args[0].value.toFixed(2)}\nUse \`/bal\` or \`/inventory wallet\` to view your cash balance`)
|
||||
.setColor('GREEN');
|
||||
|
||||
return interaction.send({ embeds: [successEmbed] });
|
||||
},
|
||||
},
|
||||
}
|
||||
Reference in new issue
Block a user