Merge pull request #6 from nxbat/try-not-to-spell-challenge

[devwatch]: devwatch button now gives more feedback.
This commit is contained in:
Tarrgon
2026-06-05 12:53:14 -04:00
committed by GitHub
2 changed files with 20 additions and 12 deletions
+13 -5
View File
@@ -4,13 +4,18 @@ import { Database } from '../shared/Database';
export default { export default {
name: 'dev-watch', name: 'dev-watch',
handler: async function (client: Client, interaction: ButtonInteraction) { handler: async function (client: Client, interaction: ButtonInteraction) {
const member = await interaction.guild!.members.fetch(interaction.user.id); try {
if (!interaction.guild) throw new Error('This action must be run in a guild.');
if (!member) return await interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'There was an error. Please try again later.' }); const settings = await Database.getGuildSettings(interaction.guild.id);
if (!settings || !settings.devwatch_role_id) throw new Error('`devwatch_role_id` was not configured. Please configure a role then try again.');
const member = await interaction.guild.members.fetch(interaction.user.id);
if (!member) throw new Error('Unable to retreive the member executing this command.');
const settings = await Database.getGuildSettings(interaction.guild!.id); const bot = await interaction.guild.members.fetchMe();
const role = await interaction.guild?.roles.fetch(settings.devwatch_role_id);
if (!settings || !settings.devwatch_role_id) return await interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'There was an error. Please try again later.' }); if (!role) throw new Error('The configured `devwatch_role_id` does not exist.');
if (role.position > bot.roles.highest.position) throw new Error('The configured `devwatch_role_id` is higher than my highest role.');
if (member.roles.cache.has(settings.devwatch_role_id)) { if (member.roles.cache.has(settings.devwatch_role_id)) {
await member.roles.remove(settings.devwatch_role_id); await member.roles.remove(settings.devwatch_role_id);
@@ -19,5 +24,8 @@ export default {
await member.roles.add(settings.devwatch_role_id); await member.roles.add(settings.devwatch_role_id);
await interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Added role.' }); await interaction.reply({ flags: [MessageFlags.Ephemeral], content: 'Added role.' });
} }
} catch (error: Error | any) {
await interaction.reply({ flags: [MessageFlags.Ephemeral], content: error.message });
}
} }
}; };
+1 -1
View File
@@ -202,7 +202,7 @@ export default {
const devWatchRole = interaction.options.getRole('devwatch-role'); const devWatchRole = interaction.options.getRole('devwatch-role');
if (devWatchRole) { if (devWatchRole) {
await Database.updateGuildSettings(interaction.guildId, 'devwatch_role_id', devWatchRole.id); await Database.updateGuildSettings(interaction.guildId, 'devwatch_role_id', devWatchRole.id);
response.push(`**private_help_role_id** has been set to ${devWatchRole}.`); response.push(`**devwatch_role_id** has been set to ${devWatchRole}.`);
} }
const addCategory = interaction.options.getChannel('add-staff-category'); const addCategory = interaction.options.getChannel('add-staff-category');