JaBa/commands/Moderation/ban.js

110 lines
3.2 KiB
JavaScript
Raw Normal View History

const Command = require("../../base/Command"),
2022-01-04 02:18:28 +05:00
Discord = require("discord.js");
class Ban extends Command {
constructor(client) {
super(client, {
name: "ban",
dirname: __dirname,
enabled: true,
guildOnly: true,
aliases: ["b"],
memberPermissions: ["BAN_MEMBERS"],
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS", "BAN_MEMBERS"],
nsfw: false,
ownerOnly: false,
cooldown: 1000
});
}
async run(message, args, data) {
const user = await this.client.resolveUser(args[0]);
if (!user) return message.error("moderation/ban:MISSING_MEMBER");
const memberData = message.guild.members.cache.get(user.id) ? await this.client.findOrCreateMember({
id: user.id,
guildID: message.guild.id
}) : null;
if (user.id === message.author.id) return message.error("moderation/ban:YOURSELF");
// If the user is already banned
const banned = await message.guild.bans.fetch();
2022-01-04 02:18:28 +05:00
if (banned.some((m) => m.user.id === user.id)) return message.error("moderation/ban:ALREADY_BANNED", {
username: user.tag
});
// Gets the ban reason
let reason = args.slice(1).join(" ");
if (!reason) reason = message.translate("misc:NO_REASON_PROVIDED");
const member = await message.guild.members.fetch(user.id).catch(() => {});
if (member) {
const memberPosition = member.roles.highest.position;
const moderationPosition = message.member.roles.highest.position;
if (message.member.ownerId !== message.author.id && !(moderationPosition > memberPosition)) return message.error("moderation/ban:SUPERIOR");
2022-01-04 02:18:28 +05:00
if (!member.bannable) return message.error("moderation/ban:MISSING_PERM");
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
await user.send(message.translate("moderation/ban:BANNED_DM", {
username: user.tag,
server: message.guild.name,
moderator: message.author.tag,
reason
})).catch(() => {});
// Ban the user
message.guild.members.ban(user, {
reason
}).then(() => {
// Send a success message in the current channel
2022-02-15 01:40:18 +05:00
message.channel.send(message.translate("moderation/ban:BANNED", {
2022-01-04 02:18:28 +05:00
username: user.tag,
server: message.guild.name,
moderator: message.author.tag,
reason
2022-02-15 01:40:18 +05:00
}));
2022-01-04 02:18:28 +05:00
const caseInfo = {
channel: message.channel.id,
moderator: message.author.id,
date: Date.now(),
type: "ban",
case: data.guild.casesCount,
reason
};
if (memberData) {
memberData.sanctions.push(caseInfo);
memberData.save();
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
data.guild.casesCount++;
data.guild.save();
if (data.guild.plugins.modlogs) {
const channel = message.guild.channels.cache.get(data.guild.plugins.modlogs);
if (!channel) return;
const embed = new Discord.MessageEmbed()
.setAuthor({
name: message.translate("moderation/ban:CASE", {
count: data.guild.casesCount
})
})
2022-01-04 02:18:28 +05:00
.addField(message.translate("common:USER"), `\`${user.tag}\` (${user.toString()})`, true)
.addField(message.translate("common:MODERATOR"), `\`${message.author.tag}\` (${message.author.toString()})`, true)
.addField(message.translate("common:REASON"), reason, true)
.setColor("#e02316");
channel.send({
embeds: [embed]
});
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
}).catch((err) => {
console.log(err);
return message.error("moderation/ban:MISSING_PERM");
});
}
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
module.exports = Ban;