const { SlashCommandBuilder, EmbedBuilder } = require('discord.js'); const UserProfile = require('../../schemas/UserProfile'); module.exports = { run: async ({ interaction }) => { if (!interaction.inGuild()) { interaction.reply({ content: "This command can only be used inside Chonsa!", ephermeral: true, }); return; } const targetUserId = interaction.options.getUser('user') ?? interaction.user; await interaction.deferReply(); try { let userProfile = await UserProfile.findOne({ userId: targetUserId.id }); if (!userProfile) { userProfile = new UserProfile({ userId: targetUserId.id }); } const balanceEmbed1 = new EmbedBuilder() .setAuthor({ name: targetUserId.username, iconURL: targetUserId.displayAvatarURL({ dynamic: true }) }) .setTitle(`${targetUserId.username}'s balance:` ) .setDescription(`<@${targetUserId.id}>'s balance is ${userProfile.balance}`) .setColor(15511231); const balanceEmbed2 = new EmbedBuilder() .setAuthor({ name: targetUserId.username, iconURL: targetUserId.displayAvatarURL({ dynamic: true }) }) .setTitle(`${targetUserId.username}'s balance:`) .setDescription(`Your balance is ${userProfile.balance}`) .setColor(15511231); if ( targetUserId === interaction.user.id ) { interaction.channel.send({ embeds: balanceEmbed2, }) interaction.editReply({ content: "balance checked!", ephermeral: true, }) } else { interaction.channel.send({ embeds: balanceEmbed1, }) interaction.editReply({ content: `<@${targetUserId.id}>'s balanced checked!`, ephermeral: true, }) } } catch (error) { console.log("Error handling /balance...", error); } }, data: new SlashCommandBuilder() .setName('balance') .setDescription(`check your or another user's balance`) .addUserOption((option) => option .setName('user') .setDescription(`who's balance would you like to see?`) ) }