2022-04-24 14:46:37 +01:00
|
|
|
import { Command } from "../type/command";
|
2023-05-26 17:59:22 +01:00
|
|
|
import Audit from "../database/entities/Audit";
|
2022-09-05 18:10:04 +01:00
|
|
|
import { AuditType } from "../constants/AuditType";
|
2022-09-18 11:57:22 +01:00
|
|
|
import { CommandInteraction, EmbedBuilder, GuildMember, PermissionsBitField, SlashCommandBuilder, TextChannel } from "discord.js";
|
|
|
|
import EmbedColours from "../constants/EmbedColours";
|
|
|
|
import SettingsHelper from "../helpers/SettingsHelper";
|
2022-04-24 14:46:37 +01:00
|
|
|
|
|
|
|
export default class Ban extends Command {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
super.CommandBuilder = new SlashCommandBuilder()
|
|
|
|
.setName("ban")
|
|
|
|
.setDescription("Ban a member from the server with an optional reason")
|
|
|
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.BanMembers)
|
|
|
|
.addUserOption(option =>
|
|
|
|
option
|
|
|
|
.setName('target')
|
|
|
|
.setDescription('The user')
|
|
|
|
.setRequired(true))
|
|
|
|
.addStringOption(option =>
|
|
|
|
option
|
|
|
|
.setName('reason')
|
|
|
|
.setDescription('The reason'));
|
|
|
|
}
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
public override async execute(interaction: CommandInteraction) {
|
|
|
|
if (!interaction.isChatInputCommand()) return;
|
|
|
|
if (!interaction.guildId) return;
|
|
|
|
if (!interaction.guild) return;
|
2022-06-05 14:11:01 +01:00
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
const targetUser = interaction.options.get('target');
|
|
|
|
const reasonInput = interaction.options.get('reason');
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
if (!targetUser || !targetUser.user || !targetUser.member) {
|
|
|
|
await interaction.reply("User not found.");
|
|
|
|
return;
|
2022-04-24 14:46:37 +01:00
|
|
|
}
|
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
const member = targetUser.member as GuildMember;
|
|
|
|
const reason = reasonInput && reasonInput.value ? reasonInput.value.toString() : "*none*";
|
|
|
|
|
|
|
|
const logEmbed = new EmbedBuilder()
|
|
|
|
.setColor(EmbedColours.Ok)
|
|
|
|
.setTitle("Member Banned")
|
|
|
|
.setDescription(`<@${targetUser.user.id}> \`${targetUser.user.tag}\``)
|
|
|
|
.addFields([
|
|
|
|
{
|
|
|
|
name: "Moderator",
|
|
|
|
value: `<@${interaction.user.id}>`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Reason",
|
|
|
|
value: reason,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
|
|
|
if (!member.bannable) {
|
|
|
|
await interaction.reply('Insufficient permissions. Please contact a moderator.');
|
|
|
|
return;
|
2022-04-24 14:46:37 +01:00
|
|
|
}
|
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
await member.ban();
|
|
|
|
await interaction.reply(`\`${targetUser.user.tag}\` has been banned.`);
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
const channelName = await SettingsHelper.GetSetting('channels.logs.mod', interaction.guildId);
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
if (!channelName) return;
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
const channel = interaction.guild.channels.cache.find(x => x.name == channelName) as TextChannel;
|
2022-09-05 18:10:04 +01:00
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
if (channel) {
|
|
|
|
await channel.send({ embeds: [ logEmbed ]});
|
2022-09-05 18:10:04 +01:00
|
|
|
}
|
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
const audit = new Audit(targetUser.user.id, AuditType.Ban, reason, interaction.user.id, interaction.guildId);
|
|
|
|
await audit.Save(Audit, audit);
|
2022-04-24 14:46:37 +01:00
|
|
|
}
|
|
|
|
}
|