changed achievment to work without followup
This commit is contained in:
+48
-8
@@ -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
|
||||||
) {
|
) {
|
||||||
try {
|
const embed =
|
||||||
await interaction.followUp({
|
|
||||||
embeds: [
|
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setTitle("🏆 Achievement Unlocked!")
|
.setTitle(
|
||||||
|
"🏆 Achievement Unlocked!"
|
||||||
|
)
|
||||||
.setDescription(
|
.setDescription(
|
||||||
[
|
[
|
||||||
`<@${userId}> earned an achievement!`,
|
`<@${userId}> earned an achievement!`,
|
||||||
"",
|
"",
|
||||||
`**${achievement.name}**`,
|
`${achievement.emoji ?? "🏆"} **${achievement.name}**`,
|
||||||
achievement.description
|
"",
|
||||||
|
achievement.description ??
|
||||||
|
achievement.requirement ??
|
||||||
|
"Achievement unlocked."
|
||||||
].join("\n")
|
].join("\n")
|
||||||
)
|
)
|
||||||
]
|
.setTimestamp();
|
||||||
|
|
||||||
|
try {
|
||||||
|
/*
|
||||||
|
* If the interaction has already been acknowledged,
|
||||||
|
* followUp is safe.
|
||||||
|
*/
|
||||||
|
if (
|
||||||
|
interaction.replied ||
|
||||||
|
interaction.deferred
|
||||||
|
) {
|
||||||
|
return await interaction.followUp({
|
||||||
|
embeds: [embed]
|
||||||
});
|
});
|
||||||
} 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(
|
||||||
|
|||||||
Reference in New Issue
Block a user