Skip to content

Commit c3a9b31

Browse files
committed
hot fixed issues
1 parent 0d3c838 commit c3a9b31

File tree

5 files changed

+91
-43
lines changed

5 files changed

+91
-43
lines changed

bot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ client.on('guildMemberAdd', async (member) => {
437437
const welcomeEmbed = new EmbedBuilder()
438438
.setTitle(`YAY! Welcome to ${member.guild.name} ${member.user.displayName}!`)
439439
.setDescription(`
440-
Yayyy! ${member.user} -sama has joined the fight to defend Earth with Son Goku and Sailor Moon.
440+
Yayyy! ${member.user}-sama has joined the fight to defend Earth with Son Goku and Sailor Moon.
441441
\nWe now have ${member.guild.memberCount} warriors to join the fight! But are you a Saiyan, a Senshi, or both?
442442
\n\n${member.user}-sama, please select your roles to identify your training grounds, your identification, and other things Goku and Usagi will need to know (they are a bit clueless).`)
443443
.setColor(0x008080)

commands/admin_commands/admin_commands.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ module.exports = {
6565

6666
// Fetch the bans from the guild
6767
try {
68+
await interaction.deferReply({ ephemeral: true });
69+
6870
const bans = await interaction.guild.bans.fetch();
6971
const bannedUser = bans.get(user.id);
7072

7173
if (!bannedUser) {
72-
return interaction.reply({ content: 'The specified user is not banned', ephemeral: true });
74+
return interaction.editReply({ content: 'The specified user is not banned', ephemeral: true });
7375
}
7476

7577
// Unban the user
@@ -81,10 +83,16 @@ module.exports = {
8183
.setColor(0x2ECC71)
8284
.addFields({ name: 'Reason', value: reason });
8385

84-
return interaction.reply({ embeds: [embed] });
86+
return interaction.editReply({ embeds: [embed] });
8587
} catch (err) {
8688
console.error('Error unbanning user:', err);
87-
return interaction.reply({ content: 'An error occurred while trying to unban the user', ephemeral: true });
89+
90+
// Check if the interaction is already acknowledged
91+
if (interaction.replied || interaction.deferred) {
92+
return interaction.followUp({ content: 'An error occurred while trying to unban the user', ephemeral: true });
93+
} else {
94+
return interaction.reply({ content: 'An error occurred while trying to unban the user', ephemeral: true });
95+
}
8896
}
8997
}
9098
},

commands/community_commands/community_commands.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,7 @@ module.exports = {
143143

144144
const userId = user.id;
145145

146-
console.log(`Part 1: Updated by ${user.username}`);
147146
await updateUserBio(serverId, userId, bio);
148-
console.log(`Part 2: Updated by ${user.username}`);
149-
// Confirmation message
150147
const confirmEmbed = new EmbedBuilder()
151148
.setColor(0x00FF00)
152149
.setTitle("Bio Updated")

commands/milestone_commands/milestone_commands.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,27 +107,48 @@ module.exports = {
107107
const guildId = interaction.guild.id;
108108

109109
try {
110+
// Fetch the user's highest role
111+
const member = interaction.guild.members.cache.get(interaction.user.id);
112+
const highestRole = member.roles.highest;
113+
110114
// Check if a milestone for this level exists in the database
111115
const existingMilestone = await MilestoneLevel.findOne({
112116
where: {
113117
guildId,
114118
level
115119
}
116120
});
117-
118-
if (!existingMilestone) { return interaction.reply({ content: `No milestone for level ${level} exists.`, ephemeral: true }); }
119-
120-
// Remove milestone level from the database
121+
122+
if (!existingMilestone) {
123+
return interaction.reply({ content: `No milestone for level ${level} exists.`, ephemeral: true });
124+
}
125+
126+
// Fetch the role associated with the milestone level
127+
const roleToRemove = interaction.guild.roles.cache.get(existingMilestone.reward);
128+
129+
if (!roleToRemove) {
130+
return interaction.reply({ content: 'The role associated with this milestone does not exist in the server.', ephemeral: true });
131+
}
132+
133+
// Check if the user's highest role is above or below the milestone role
134+
if (highestRole.position <= roleToRemove.position) {
135+
return interaction.reply({ content: 'You cannot remove a milestone role that is higher or equal to your own highest role.', ephemeral: true });
136+
}
137+
138+
// If all checks are passed, remove milestone level from the database
121139
await existingMilestone.destroy();
122-
140+
123141
const embed = new EmbedBuilder()
124142
.setColor(0x008080)
125143
.setTitle('Milestone Removed')
126144
.setDescription(`Milestone for level ${level} has been removed.`)
127145
.setTimestamp();
128-
129-
return interaction.reply({ embeds: embed });
130-
} catch (error) { return interaction.reply({ content: 'An error occurred while removing the milestone. Please try again later.', ephemeral: true }); }
146+
147+
return interaction.reply({ embeds: [embed] });
148+
} catch (error) {
149+
console.error('Error removing milestone:', error);
150+
return interaction.reply({ content: 'An error occurred while removing the milestone. Please try again later.', ephemeral: true });
151+
}
131152
}
132153
},
133154

commands/utils.js

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -96,38 +96,60 @@ async function checkAndGrantMilestoneRoles(member, guildId, level, message) {
9696
let roleGranted = false;
9797

9898
// Go through each milestone and check if the user has the role
99-
for (const milestone of milestones) {
100-
const role = member.guild.roles.cache.get(milestone.reward);
101-
if (!role) {
102-
continue;
103-
}
104-
105-
// Check if the member already has the role
106-
if (!member.roles.cache.has(role.id)) {
107-
// Add the role if missing
108-
await member.roles.add(role);
109-
110-
if (rankUpChannel) {
111-
const embed = new EmbedBuilder()
112-
.setTitle('Transformation!')
113-
.setDescription(`🎉 <@${member.user.id}> has been granted <@&${role.id}> for reaching level ${milestone.level}! 🎉`)
114-
.setColor(0x008080);
99+
100+
// if milestone role exists, go through for loop
101+
if (milestones.length > 0) {
102+
for (const milestone of milestones) {
103+
const role = member.guild.roles.cache.get(milestone.reward);
104+
if (!role) {
105+
continue;
106+
}
115107

116-
rankUpChannel.send({ embeds: [embed] });
108+
// Check if the member already has the role
109+
if (!member.roles.cache.has(role.id)) {
110+
// Add the role if missing
111+
await member.roles.add(role);
112+
113+
if (rankUpChannel) {
114+
const embed = new EmbedBuilder()
115+
.setTitle('🎉 **Transformation Reached!** 🎉')
116+
.setDescription(`
117+
### <@${member.user.id}> has been granted <@&${role.id}> for reaching Level ${milestone.level}!
118+
119+
**Keep training to reach the next transformation!**
120+
`)
121+
.setImage(`https://tenor.com/en-GB/view/sailor-moon-anime-moon-prism-power-moon-prism-power-makeup-serena-gif-15851654.gif`)
122+
.setColor(0x008080);
123+
124+
rankUpChannel.send({ embeds: [embed] });
125+
}
126+
} else {
127+
if (rankUpChannel) {
128+
const embed = new EmbedBuilder()
129+
.setTitle('🎉 **Transformation Reached!** 🎉')
130+
.setDescription(`
131+
**<@${member.user.id}> has been granted <@&${role.id}> for reaching Level ${milestone.level}!**
132+
133+
Keep training to reach the next transformation!
134+
`)
135+
.setImage(`https://tenor.com/en-GB/view/sailor-moon-anime-moon-prism-power-moon-prism-power-makeup-serena-gif-15851654.gif`)
136+
.setColor(0x008080);
137+
138+
rankUpChannel.send({ embeds: [embed] });
139+
}
117140
}
118141
}
142+
} else {
143+
// Send a message even if no milestone role was granted
144+
if (!roleGranted && rankUpChannel) {
145+
const embed = new EmbedBuilder()
146+
.setTitle('Keep Training!')
147+
.setDescription(`Great job, <@${member.user.id}>! You're currently at level ${level}. Keep training to reach the next transformation!`)
148+
.setColor(0xFFD700);
149+
150+
rankUpChannel.send({ embeds: [embed] });
151+
}
119152
}
120-
121-
// Send a message even if no milestone role was granted
122-
if (!roleGranted && rankUpChannel) {
123-
const embed = new EmbedBuilder()
124-
.setTitle('Keep Training!')
125-
.setDescription(`Great job, <@${member.user.id}>! You're currently at level ${level}. Keep training to reach the next transformation!`)
126-
.setColor(0xFFD700);
127-
128-
rankUpChannel.send({ embeds: [embed] });
129-
}
130-
131153
} catch (err) {
132154
console.error(`Error checking and granting milestone roles for user ${member.user.username}:`, err);
133155
}

0 commit comments

Comments
 (0)