Skip to content

Commit

Permalink
feat: add delete helper role command
Browse files Browse the repository at this point in the history
  • Loading branch information
hendraaagil committed Jan 13, 2024
1 parent 0699b4e commit 9ef93cf
Showing 1 changed file with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed } = require('discord.js');
const { checkRoles } = require('../modules/utility');

const KETUA_KELAS_ID = process.env.ROLE_KETUA;

exports.command = new SlashCommandBuilder()
.setName('add-helper-role')
.setName('helper-role')
.setDescription('Add helper role command')
.addStringOption((option) =>
option
.setName('action')
.setDescription('Select an action')
.setRequired(true)
.addChoice('Add', 'add')
.addChoice('Remove', 'remove'),
)
.addRoleOption((option) => option.setName('role').setDescription('Select a role').setRequired(true));

exports.permissions = [
Expand All @@ -27,18 +34,30 @@ exports.execute = async (interaction) => {
return interaction.reply({ content: 'Invalid role!', ephemeral: true });
}

const action = interaction.options.getString('action');
const prisma = interaction.client.prisma;
const existingRole = await prisma.helper_role.findUnique({ where: { role_id: role.id } });
if (existingRole) {

if (existingRole && action === 'add') {
return interaction.reply({ content: 'Role already exists!', ephemeral: true });
}
if (!existingRole && action === 'remove') {
return interaction.reply({ content: 'Role does not exist!', ephemeral: true });
}

await prisma.helper_role.create({
data: {
role_id: role.id,
added_by: interaction.user.id,
},
});
if (action === 'add') {
await prisma.helper_role.create({
data: {
role_id: role.id,
added_by: interaction.user.id,
},
});

await interaction.reply({ content: 'Role added!', ephemeral: true });
return interaction.reply({ content: 'Role added!', ephemeral: true });
}

if (action === 'remove') {
await prisma.helper_role.delete({ where: { role_id: role.id } });
return interaction.reply({ content: 'Role removed!', ephemeral: true });
}
};

0 comments on commit 9ef93cf

Please sign in to comment.