Haha-Yes/commands/owner/ublacklist.js

75 lines
2.5 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,
2022-10-13 15:49:31 +02:00
async execute(interaction, args) {
await interaction.deferReply({ ephemeral: true });
const client = interaction.client;
2022-10-13 15:49:31 +02:00
const command = args.command;
const userid = args.userid;
const reason = args.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;
2022-10-13 15:55:56 +02:00
if (command !== 'guild') {
await client.users.resolve(userid);
user = client.users.fetch(userid).tag;
}
return interaction.editReply(`${user} has been blacklisted from ${command} with the following reason ${reason}`);
}
else {
const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
2022-09-14 11:31:19 +02:00
.setCustomId(`yes${interaction.user.id}`)
.setLabel('Yes')
.setStyle(ButtonStyle.Primary),
)
.addComponents(
new ButtonBuilder()
2022-09-14 11:31:19 +02:00
.setCustomId(`no${interaction.user.id}`)
.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: [] });
2022-09-14 11:31:19 +02:00
if (interactionMenu.customId === `yes${interaction.user.id}`) {
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.');
}
});
}
},
};