Haha-Yes/commands/owner/ublacklist.js

72 lines
2.4 KiB
JavaScript
Raw Normal View History

import { ButtonStyle, SlashCommandBuilder, ButtonBuilder, ActionRowBuilder } from 'discord.js';
import db from '../../models/index.js';
const Blacklists = db.Blacklists;
export default {
data: new SlashCommandBuilder()
.setName('ublacklist')
.setDescription('Blacklist a user from the bot')
.addStringOption(option =>
option.setName('command')
.setDescription('Which command do you want to get a user blacklisted from?')
.setRequired(true))
.addStringOption(option =>
option.setName('userid')
.setDescription('Who do you want to blacklist?')
.setRequired(true))
.addStringOption(option =>
option.setName('reason')
.setDescription('The reason of the blacklist.')
.setRequired(false)),
category: 'owner',
ownerOnly: true,
async execute(interaction) {
await interaction.deferReply({ ephemeral: true });
const client = interaction.client;
const command = interaction.options.getString('command');
const userid = interaction.options.getString('userid');
const reason = interaction.options.getString('reason');
const blacklist = await Blacklists.findOne({ where: { type:command, uid:userid } });
if (!blacklist) {
const body = { type:command, uid: userid, reason: reason };
Blacklists.create(body);
let user = userid;
if (command !== 'guild') {user = client.users.resolve(userid).tag;}
return interaction.editReply(`${user} has been blacklisted from ${command} with the following reason ${reason}`);
}
else {
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('yes')
.setLabel('Yes')
.setStyle(ButtonStyle.Primary),
)
.addComponents(
new ButtonBuilder()
.setCustomId('no')
.setLabel('No')
.setStyle(ButtonStyle.Danger),
);
await interaction.editReply({ content: 'This user is already blacklisted, do you want to unblacklist him?', ephemeral: true, components: [row] });
2022-09-10 09:35:32 +02:00
interaction.client.on('interactionCreate', async (interactionMenu) => {
if (interaction.user !== interactionMenu.user) return;
if (!interactionMenu.isButton) return;
interactionMenu.update({ components: [] });
if (interactionMenu.customId === 'yes') {
Blacklists.destroy({ where: { type:command, uid:userid } });
return interaction.editReply(`The following ID have been unblacklisted from ${command}: ${userid}`);
}
else {
return interaction.editReply('No one has been unblacklisted.');
}
});
}
},
};