From 6a519f3a2d6c4d350adc790c51d864b28ba9de65 Mon Sep 17 00:00:00 2001 From: DeSqBlocki Date: Sun, 23 Aug 2026 01:19:22 +0200 Subject: [PATCH] changed achievment to work without followup --- utils/profileSystem.js | 70 +++++++++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 15 deletions(-) diff --git a/utils/profileSystem.js b/utils/profileSystem.js index 1d83e3d..6e661a1 100644 --- a/utils/profileSystem.js +++ b/utils/profileSystem.js @@ -738,6 +738,7 @@ async function unlockAchievement( await sendAchievementNotification( interaction, + userId, definition ); @@ -775,24 +776,63 @@ function readStatValue( async function sendAchievementNotification( interaction, + userId, achievement ) { + const embed = + new EmbedBuilder() + .setTitle( + "🏆 Achievement Unlocked!" + ) + .setDescription( + [ + `<@${userId}> earned an achievement!`, + "", + `${achievement.emoji ?? "🏆"} **${achievement.name}**`, + "", + achievement.description ?? + achievement.requirement ?? + "Achievement unlocked." + ].join("\n") + ) + .setTimestamp(); + try { - await interaction.followUp({ - embeds: [ - new EmbedBuilder() - .setTitle("🏆 Achievement Unlocked!") - .setDescription( - [ - `<@${userId}> earned an achievement!`, - "", - `**${achievement.name}**`, - achievement.description - ].join("\n") - ) - ] - }); - } catch { } + /* + * If the interaction has already been acknowledged, + * followUp is safe. + */ + if ( + interaction.replied || + interaction.deferred + ) { + return await interaction.followUp({ + embeds: [embed] + }); + } + + /* + * Otherwise don't consume the interaction's primary + * reply. The game/button handler still needs it. + * + * Send the public achievement announcement directly + * to the channel instead. + */ + if (interaction.channel) { + return await interaction.channel.send({ + embeds: [embed] + }); + } + } + + catch (error) { + console.error( + `[Achievement] Failed to announce ${achievement.achievementId} for ${userId}:`, + error + ); + } + + return null; } async function evaluateBadges(