JaBa/commands/Moderation/unban.js

57 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-12-10 21:39:54 +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: [ "deban", "déban" ],
memberPermissions: [ "BAN_MEMBERS" ],
botPermissions: [ "SEND_MESSAGES", "EMBED_LINKS", "BAN_MEMBERS" ],
nsfw: false,
ownerOnly: false,
cooldown: 3000
});
}
async run (message, args) {
let user = null;
2021-12-11 01:11:50 +05:00
if (!args[0]) return message.error("moderation/unban:MISSING_ID");
2021-12-10 21:39:54 +05:00
// Check if the arg is an ID or a username
const isId = !isNaN(args[0]);
2021-12-11 01:11:50 +05:00
if (isId) {
2021-12-10 21:39:54 +05:00
// 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("#");
2021-12-11 01:11:50 +05:00
if (arr.length < 2) {
2021-12-10 21:39:54 +05:00
return message.error("misc:NO_USER_FOUND_ID", {
id: args[0]
});
2021-12-11 01:11:50 +05:00
};
2021-12-10 21:39:54 +05:00
user = this.client.users.filter((u) => u.username === arr[0]).find((u) => u.discriminator === arr[1]);
2021-12-11 01:11:50 +05:00
};
2021-12-10 21:39:54 +05:00
2021-12-11 01:11:50 +05:00
if (!user) return message.error("misc:NO_USER_FOUND_ID", { id: args[0] });
2021-12-10 21:39:54 +05:00
// check if the user is banned
const banned = await message.guild.fetchBans();
2021-12-11 01:11:50 +05:00
if (!banned.some((e) => e.user.id === user.id)) return message.success("moderation/unban:NOT_BANNED", { username: user.tag });
2021-12-10 21:39:54 +05:00
// Unban user
message.guild.members.unban(user).catch(() => {});
// Send a success message in the current channel
2021-12-11 01:11:50 +05:00
message.success("moderation/unban:UNBANNED", { username: user.tag, server: message.guild.name });
2021-12-10 21:39:54 +05:00
}
2021-12-11 01:11:50 +05:00
};
2021-12-10 21:39:54 +05:00
module.exports = Unban;