JaBa/commands/Moderation/unban.js

60 lines
1.5 KiB
JavaScript
Raw Normal View History

2022-01-04 02:18:28 +05:00
const Command = require("../../base/Command.js");
class Unban extends Command {
constructor(client) {
super(client, {
name: "unban",
dirname: __dirname,
enabled: true,
guildOnly: true,
aliases: ["ub"],
memberPermissions: ["BAN_MEMBERS"],
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS", "BAN_MEMBERS"],
nsfw: false,
ownerOnly: false,
cooldown: 1000
});
}
async run(message, args) {
let user = null;
if (!args[0]) return message.error("moderation/unban:MISSING_ID");
// Check if the arg is an ID or a username
const isId = !isNaN(args[0]);
if (isId) {
// Try to find a user with that ID
await this.client.users.fetch(args[0]).then((u) => {
// if a user was found
user = u;
}).catch(() => {});
} else if (!isId) {
const arr = args[0].split("#");
if (arr.length < 2) {
return message.error("misc:NO_USER_FOUND_ID", {
id: args[0]
});
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
user = this.client.users.filter((u) => u.username === arr[0]).find((u) => u.discriminator === arr[1]);
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
if (!user) return message.error("misc:NO_USER_FOUND_ID", { id: args[0] });
// check if the user is banned
const banned = await message.guild.bans.fetch();
2022-01-04 02:18:28 +05:00
if (!banned.some((e) => e.user.id === user.id)) return message.success("moderation/unban:NOT_BANNED", { username: user.tag });
// Unban user
message.guild.members.unban(user).catch(() => {});
// Send a success message in the current channel
message.success("moderation/unban:UNBANNED", {
username: user.tag,
server: message.guild.name
});
}
2022-01-13 00:26:23 +05:00
}
2022-01-04 02:18:28 +05:00
module.exports = Unban;