refactor: Remove interaction deferrals, use direct replies, and make error/warning messages ephemeral in economy commands.
This commit is contained in:
@@ -9,8 +9,6 @@ export const daily = createCommand({
|
||||
.setName("daily")
|
||||
.setDescription("Claim your daily reward"),
|
||||
execute: async (interaction) => {
|
||||
await interaction.deferReply();
|
||||
|
||||
try {
|
||||
const result = await economyService.claimDaily(interaction.user.id);
|
||||
|
||||
@@ -24,16 +22,16 @@ export const daily = createCommand({
|
||||
.setColor("Gold")
|
||||
.setTimestamp();
|
||||
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
await interaction.reply({ embeds: [embed] });
|
||||
|
||||
} catch (error: any) {
|
||||
if (error.message.includes("Daily already claimed")) {
|
||||
await interaction.editReply({ embeds: [createWarningEmbed(error.message, "Cooldown")] });
|
||||
await interaction.reply({ embeds: [createWarningEmbed(error.message, "Cooldown")], ephemeral: true });
|
||||
return;
|
||||
}
|
||||
|
||||
console.error(error);
|
||||
await interaction.editReply({ embeds: [createErrorEmbed("An error occurred while claiming your daily reward.")] });
|
||||
await interaction.reply({ embeds: [createErrorEmbed("An error occurred while claiming your daily reward.")], ephemeral: true });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -21,20 +21,18 @@ export const pay = createCommand({
|
||||
.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 (amount < GameConfig.economy.transfers.minAmount) {
|
||||
await interaction.editReply({ embeds: [createWarningEmbed(`Amount must be at least ${GameConfig.economy.transfers.minAmount}.`)] });
|
||||
await interaction.reply({ embeds: [createWarningEmbed(`Amount must be at least ${GameConfig.economy.transfers.minAmount}.`)], ephemeral: true });
|
||||
return;
|
||||
}
|
||||
|
||||
if (senderId === receiverId) {
|
||||
await interaction.editReply({ embeds: [createWarningEmbed("You cannot pay yourself.")] });
|
||||
await interaction.reply({ embeds: [createWarningEmbed("You cannot pay yourself.")], ephemeral: true });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -47,15 +45,15 @@ export const pay = createCommand({
|
||||
.setColor("Green")
|
||||
.setTimestamp();
|
||||
|
||||
await interaction.editReply({ embeds: [embed] });
|
||||
await interaction.reply({ embeds: [embed] });
|
||||
|
||||
} catch (error: any) {
|
||||
if (error.message.includes("Insufficient funds")) {
|
||||
await interaction.editReply({ embeds: [createWarningEmbed("Insufficient funds.")] });
|
||||
await interaction.reply({ embeds: [createWarningEmbed("Insufficient funds.")], ephemeral: true });
|
||||
return;
|
||||
}
|
||||
console.error(error);
|
||||
await interaction.editReply({ embeds: [createErrorEmbed("Transfer failed.")] });
|
||||
await interaction.reply({ embeds: [createErrorEmbed("Transfer failed.")], ephemeral: true });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -49,7 +49,12 @@ export const trade = createCommand({
|
||||
} catch (e) {
|
||||
// Fallback if message threads fail, try channel threads (private preferred)
|
||||
// But startThread on message is usually easiest.
|
||||
await interaction.editReply({ content: "", embeds: [createErrorEmbed("Failed to create trade thread. Check permissions.")] });
|
||||
try {
|
||||
await message.delete();
|
||||
} catch (err) {
|
||||
console.error("Failed to delete setup message", err);
|
||||
}
|
||||
await interaction.followUp({ embeds: [createErrorEmbed("Failed to create trade thread. Check permissions.")], ephemeral: true });
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user