Polarcraft/discordbot/commands/removewhitelist.js

32 lines
1.2 KiB
JavaScript
Raw Normal View History

2023-08-04 19:27:29 +02:00
const { SlashCommandBuilder } = require('discord.js');
const { simpleEmbed } = require('../functions/embeds.js');
const { Minecraft, Users } = require('../functions/models.js');
2023-08-05 11:16:18 +02:00
const { applyUsername } = require('../functions/utils.js');
2023-08-04 19:27:29 +02:00
module.exports = {
data: new SlashCommandBuilder()
.setName('removewhitelist')
.setDescription('Remove yourself from the whitelist'),
async execute(interaction) {
try {
const user = await Users.findOne({ where: { id: interaction.user.id } });
2023-08-11 11:14:59 +02:00
if (!user.minecraftUuid) return await interaction.reply({ embeds: [simpleEmbed('You are not whitelisted')], ephemeral: true });
2023-08-04 19:27:29 +02:00
2023-08-11 11:14:59 +02:00
await Minecraft.destroy({ where: { uuid: user.minecraftUuid } });
2023-08-04 19:27:29 +02:00
2023-08-05 11:16:18 +02:00
await applyUsername(user, interaction.member);
2023-08-11 11:14:59 +02:00
const role = await interaction.guild.roles.fetch(process.env.MINECRAFT_ROLE_ID);
await interaction.member.roles.remove(role);
2023-08-04 19:27:29 +02:00
await interaction.reply({ embeds: [simpleEmbed('Successfully removed you from the whitelist')], ephemeral: true });
} catch (error) {
console.error(error);
2023-08-05 11:16:18 +02:00
await interaction.reply({ embeds: [simpleEmbed('There was an error while removing you from the whitelist')], ephemeral: true });
2023-08-04 19:27:29 +02:00
}
},
};