JaBa/commands/Economy/money.js

87 lines
2.9 KiB
JavaScript
Raw Permalink Normal View History

const { SlashCommandBuilder } = require("discord.js");
2022-08-09 23:48:33 +05:00
const BaseCommand = require("../../base/BaseCommand");
2022-08-09 23:48:33 +05:00
class Money extends BaseCommand {
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../base/Client")} client
2022-08-09 23:48:33 +05:00
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("money")
.setDescription(client.translate("economy/money:DESCRIPTION"))
.setDescriptionLocalizations({
2023-07-05 00:58:06 +05:00
uk: client.translate("economy/money:DESCRIPTION", null, "uk-UA"),
ru: client.translate("economy/money:DESCRIPTION", null, "ru-RU"),
})
.setDMPermission(false)
2023-07-05 00:58:06 +05:00
.addUserOption(option =>
option
.setName("user")
.setDescription(client.translate("common:USER"))
.setDescriptionLocalizations({
uk: client.translate("common:USER", null, "uk-UA"),
ru: client.translate("common:USER", null, "ru-RU"),
}),
),
2022-08-09 23:48:33 +05:00
dirname: __dirname,
ownerOnly: false,
2022-08-09 23:48:33 +05:00
});
}
2022-08-09 23:48:33 +05:00
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../../base/Client")} client
2022-08-09 23:48:33 +05:00
* @param {import("discord.js").ChatInputCommandInteraction} interaction
*/
2024-02-09 23:26:57 +05:00
async execute(client, interaction) {
2022-08-09 23:48:33 +05:00
await interaction.deferReply();
2022-08-09 23:48:33 +05:00
const member = interaction.options.getMember("user") || interaction.member;
if (member.user.bot) return interaction.error("economy/money:BOT_USER");
const memberData = member.id === interaction.user.id ? interaction.data.member : await client.getMemberData(member.id, interaction.guildId);
2022-08-09 23:48:33 +05:00
const guilds = client.guilds.cache.filter(g => g.members.cache.find(m => m.id === member.id));
2024-02-09 23:26:57 +05:00
2022-08-09 23:48:33 +05:00
let globalMoney = 0;
await client.functions.asyncForEach(guilds, async guild => {
const data = await client.getMemberData(member.id, guild.id);
2022-08-09 23:48:33 +05:00
globalMoney += data.money + data.bankSold;
});
const embed = client.embed({
author: {
2022-08-09 23:48:33 +05:00
name: interaction.translate("economy/money:TITLE", {
user: member.user.getUsername(),
2022-08-09 23:48:33 +05:00
}),
iconURL: member.user.displayAvatarURL(),
},
fields: [
2022-08-09 23:48:33 +05:00
{
name: interaction.translate("economy/profile:CASH"),
value: `**${memberData.money}** ${client.functions.getNoun(memberData.money, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
inline: true,
2022-08-09 23:48:33 +05:00
},
{
name: interaction.translate("economy/profile:BANK"),
value: `**${memberData.bankSold}** ${client.functions.getNoun(memberData.bankSold, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
inline: true,
2022-08-09 23:48:33 +05:00
},
{
name: interaction.translate("economy/profile:GLOBAL"),
value: `**${globalMoney}** ${client.functions.getNoun(globalMoney, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
inline: true,
},
],
});
2022-08-09 23:48:33 +05:00
interaction.editReply({
embeds: [embed],
2022-08-09 23:48:33 +05:00
});
}
}
2023-07-05 00:58:06 +05:00
module.exports = Money;