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')?.id || interaction.user.id; await interaction.deferReply(); try { let userProfile = await UserProfile.findOne({ userId: targetUserId }); if (!userProfile) { userProfile = new UserProfile({ userId: targetUserId }); } const optionUserEmbed = new EmbedBuilder() .setAuthor({ name: interaction.options.getUser('user').username, iconURL: interaction.options.getUser('user').displayAvatarURL({ dynamic: true }) }) .setTitle(`${interaction.options.getUser('user').username}'s balance:` ) .setDescription(`<@${interaction.options.getUser('user').username}>'s balance is ${userProfile.balance}`) .setColor(15511231); const interactionUserEmbed = new EmbedBuilder() .setAuthor({ name: interaction.user.username, iconURL: interaction.user.displayAvatarURL({ dynamic: true }) }) .setTitle(`${interaction.user.username}'s balance:`) .setDescription(`Your balance is ${userProfile.balance}`) .setColor(15511231); if ( targetUserId === interaction.user.id ) { interaction.channel.send({ embeds: interactionUserEmbed, }) interaction.editReply({ content: "balance checked!", ephermeral: true, }) } else { interaction.channel.send({ embeds: optionsUserEmbed, }) interaction.editReply({ content: `<@${interaction.options.getUser('user')}>'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?`) )