changed achievment to work without followup

This commit is contained in:
DeSqBlocki
2026-08-23 01:19:22 +02:00
parent 338b32430d
commit 6a519f3a2d
+55 -15
View File
@@ -738,6 +738,7 @@ async function unlockAchievement(
await sendAchievementNotification( await sendAchievementNotification(
interaction, interaction,
userId,
definition definition
); );
@@ -775,24 +776,63 @@ function readStatValue(
async function sendAchievementNotification( async function sendAchievementNotification(
interaction, interaction,
userId,
achievement 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 { try {
await interaction.followUp({ /*
embeds: [ * If the interaction has already been acknowledged,
new EmbedBuilder() * followUp is safe.
.setTitle("🏆 Achievement Unlocked!") */
.setDescription( if (
[ interaction.replied ||
`<@${userId}> earned an achievement!`, interaction.deferred
"", ) {
`**${achievement.name}**`, return await interaction.followUp({
achievement.description embeds: [embed]
].join("\n") });
) }
]
}); /*
} catch { } * 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( async function evaluateBadges(