import { createCommand } from "@/lib/utils"; import { SlashCommandBuilder, EmbedBuilder } from "discord.js"; import { economyService } from "@/modules/economy/economy.service"; import { userService } from "@/modules/user/user.service"; export const pay = createCommand({ data: new SlashCommandBuilder() .setName("pay") .setDescription("Transfer coins to another user") .addUserOption(option => option.setName("user") .setDescription("The user to pay") .setRequired(true) ) .addIntegerOption(option => option.setName("amount") .setDescription("Amount to transfer") .setMinValue(1) .setRequired(true) ), execute: async (interaction) => { await interaction.deferReply(); const targetUser = await userService.getOrCreateUser(interaction.options.getUser("user", true).id, interaction.options.getUser("user", true).username); const amount = BigInt(interaction.options.getInteger("amount", true)); const senderId = interaction.user.id; const receiverId = targetUser.id; if (senderId === receiverId) { await interaction.editReply({ content: "❌ You cannot pay yourself." }); return; } try { await economyService.transfer(senderId, receiverId, amount); const embed = new EmbedBuilder() .setTitle("💸 Transfer Successful") .setDescription(`Successfully sent **${amount}** coins to ${targetUser}.`) .setColor("Green") .setTimestamp(); await interaction.editReply({ embeds: [embed] }); } catch (error: any) { if (error.message.includes("Insufficient funds")) { await interaction.editReply({ content: "❌ Insufficient funds." }); return; } console.error(error); await interaction.editReply({ content: "❌ Transfer failed." }); } } });