103 lines
3.2 KiB
JavaScript
103 lines
3.2 KiB
JavaScript
const { MessageEmbed, Guild } = require('discord.js');
|
|
|
|
module.exports = {
|
|
name: "bal",
|
|
debug: false,
|
|
description: "View balance",
|
|
usage: "[user]",
|
|
permissions: {
|
|
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
|
member: [],
|
|
},
|
|
SlashCommand: {
|
|
options: [
|
|
{
|
|
name: "user",
|
|
description: "user to view ballance",
|
|
value: "user",
|
|
type: 6,
|
|
required: false,
|
|
}
|
|
],
|
|
/**
|
|
*
|
|
* @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 balanceEmbed = new MessageEmbed()
|
|
.setColor(client.config.EmbedColor);
|
|
|
|
if (args&&args[0]) {
|
|
// Show target users balance
|
|
|
|
let targetUserID = args[0].value.replace('<@!', '').replace('>', '');
|
|
let targetUserBanking = await client.dbo.collection("banking").findOne({"account.userID":targetUserID}).then(inventory => inventory);
|
|
|
|
if (!targetUserBanking) {
|
|
targetUserBanking = {
|
|
account: {
|
|
userID: interaction.member.user.id,
|
|
balance: GuildDB.startingBalance,
|
|
cash: 0.00,
|
|
}
|
|
}
|
|
|
|
client.dbo.collection("banking").insertOne(targetUserBanking, function(err, res) {
|
|
if (err) {
|
|
client.log(err);
|
|
let embed = new MessageEmbed()
|
|
.setTitle(err)
|
|
.setColor("RED")
|
|
|
|
return interaction.send({ embeds: [embed] });
|
|
}
|
|
});
|
|
}
|
|
|
|
// This lame line of code to get username without ping on discord
|
|
const User = client.users.cache.get(targetUserID);
|
|
|
|
balanceEmbed.setTitle(`${User.tag}'s Balance`);
|
|
balanceEmbed.setDescription(`**Bank:** $${targetUserBanking.account.balance}\n**Cash:** $${targetUserBanking.account.cash}`);
|
|
|
|
} else {
|
|
// Show command authors balance
|
|
|
|
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] });
|
|
}
|
|
});
|
|
}
|
|
|
|
balanceEmbed.setTitle('Your Balance');
|
|
balanceEmbed.setDescription(`**Bank:** $${banking.account.balance.toFixed(2)}\n**Cash:** $${banking.account.cash.toFixed(2)}`);
|
|
}
|
|
|
|
return interaction.send({ embeds: [balanceEmbed] });
|
|
},
|
|
},
|
|
} |