Files
aurorabot/src/commands/economy/daily.ts

37 lines
1.5 KiB
TypeScript

import { createCommand } from "@/lib/utils";
import { SlashCommandBuilder, EmbedBuilder } from "discord.js";
import { economyService } from "@/modules/economy/economy.service";
import { createErrorEmbed, createWarningEmbed } from "@lib/embeds";
export const daily = createCommand({
data: new SlashCommandBuilder()
.setName("daily")
.setDescription("Claim your daily reward"),
execute: async (interaction) => {
try {
const result = await economyService.claimDaily(interaction.user.id);
const embed = new EmbedBuilder()
.setTitle("💰 Daily Reward Claimed!")
.setDescription(`You claimed **${result.amount}** Astral Units!`)
.addFields(
{ name: "Streak", value: `🔥 ${result.streak} days`, inline: true },
{ name: "Next Reward", value: `<t:${Math.floor(result.nextReadyAt.getTime() / 1000)}:R>`, inline: true }
)
.setColor("Gold")
.setTimestamp();
await interaction.reply({ embeds: [embed] });
} catch (error: any) {
if (error.message.includes("Daily already claimed")) {
await interaction.reply({ embeds: [createWarningEmbed(error.message, "Cooldown")], ephemeral: true });
return;
}
console.error(error);
await interaction.reply({ embeds: [createErrorEmbed("An error occurred while claiming your daily reward.")], ephemeral: true });
}
}
});