forked from syntaxbullet/AuroraBot-discord
34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
import { createCommand } from "@shared/lib/utils";
|
|
import { SlashCommandBuilder } from "discord.js";
|
|
import { userService } from "@shared/modules/user/user.service";
|
|
import { createBaseEmbed } from "@lib/embeds";
|
|
|
|
export const balance = createCommand({
|
|
data: new SlashCommandBuilder()
|
|
.setName("balance")
|
|
.setDescription("Check your or another user's balance")
|
|
.addUserOption(option =>
|
|
option.setName("user")
|
|
.setDescription("The user to check")
|
|
.setRequired(false)
|
|
),
|
|
execute: async (interaction) => {
|
|
await interaction.deferReply();
|
|
|
|
const targetUser = interaction.options.getUser("user") || interaction.user;
|
|
|
|
if (targetUser.bot) {
|
|
return;
|
|
}
|
|
|
|
const user = await userService.getOrCreateUser(targetUser.id, targetUser.username);
|
|
|
|
if (!user) throw new Error("Failed to retrieve user data.");
|
|
|
|
const embed = createBaseEmbed(undefined, `**Balance**: ${user.balance || 0n} AU`, "Yellow")
|
|
.setAuthor({ name: targetUser.username, iconURL: targetUser.displayAvatarURL() });
|
|
|
|
await interaction.editReply({ embeds: [embed] });
|
|
}
|
|
});
|