feat(commands): improve error feedback for economy and admin commands

This commit is contained in:
syntaxbullet
2025-12-22 12:59:46 +01:00
parent fbcac51370
commit 0dea266a6d
4 changed files with 42 additions and 27 deletions

View File

@@ -1,9 +1,10 @@
```typescript
import { createCommand } from "@/lib/utils";
import { SlashCommandBuilder, EmbedBuilder, MessageFlags } from "discord.js";
import { economyService } from "@/modules/economy/economy.service";
import { userService } from "@/modules/user/user.service";
import { config } from "@/lib/config";
import { createErrorEmbed, createWarningEmbed } from "@/lib/embeds";
import { createSuccessEmbed, createErrorEmbed } from "@lib/embeds";
import { UserError } from "@/lib/errors";
export const pay = createCommand({
@@ -26,7 +27,7 @@ export const pay = createCommand({
const discordUser = interaction.options.getUser("user", true);
if (discordUser.bot) {
await interaction.reply({ embeds: [createWarningEmbed("You cannot send money to bots.")], flags: MessageFlags.Ephemeral });
await interaction.reply({ embeds: [createErrorEmbed("You cannot send money to bots.")], flags: MessageFlags.Ephemeral });
return;
}
@@ -35,33 +36,35 @@ export const pay = createCommand({
const receiverId = targetUser.id;
if (amount < config.economy.transfers.minAmount) {
await interaction.reply({ embeds: [createWarningEmbed(`Amount must be at least ${config.economy.transfers.minAmount}.`)], flags: MessageFlags.Ephemeral });
await interaction.reply({ embeds: [createErrorEmbed(`Amount must be at least ${ config.economy.transfers.minAmount }.`)], flags: MessageFlags.Ephemeral });
return;
}
if (senderId === receiverId) {
await interaction.reply({ embeds: [createWarningEmbed("You cannot pay yourself.")], flags: MessageFlags.Ephemeral });
await interaction.reply({ embeds: [createErrorEmbed("You cannot pay yourself.")], flags: MessageFlags.Ephemeral });
return;
}
try {
await interaction.deferReply({ ephemeral: true });
await economyService.transfer(senderId, receiverId, amount);
const embed = new EmbedBuilder()
.setTitle("💸 Transfer Successful")
.setDescription(`Successfully sent **${amount}** Astral Units to <@${targetUser.id}>.`)
.setDescription(`Successfully sent ** ${ amount }** Astral Units to < @${ targetUser.id }>.`)
.setColor("Green")
.setTimestamp();
await interaction.reply({ embeds: [embed] });
await interaction.editReply({ embeds: [embed] });
} catch (error: any) {
if (error instanceof UserError) {
await interaction.reply({ embeds: [createWarningEmbed(error.message)], flags: MessageFlags.Ephemeral });
return;
await interaction.editReply({ embeds: [createErrorEmbed(error.message)] });
} else {
console.error("Error sending payment:", error);
await interaction.editReply({ embeds: [createErrorEmbed("An unexpected error occurred.")] });
}
console.error(error);
await interaction.reply({ embeds: [createErrorEmbed("Transfer failed due to an unexpected error.")], flags: MessageFlags.Ephemeral });
}
}
});
```