woomy/src/commands/kick.js

88 lines
2.6 KiB
JavaScript
Raw Normal View History

2020-01-25 10:02:43 +00:00
exports.run = async (client, message, args) => {
const settings = client.getSettings(message.guild.id);
if(!args[0]) {
return message.channel.send("<:error:466995152976871434> Who am I meant to kick?")
}
let user = message.mentions.members.first();
if (!user) {
let users;
users = client.searchForMembers(message.guild, args[0]);
if (users.length > 1)
return message.channel.send(
"<:error:466995152976871434> Found multiple users! Please be more specific or mention the user instead."
);
else if (users.length == 0)
return message.channel.send(
"<:error:466995152976871434> That user doesn't seem to exist. Try again!"
);
user = users[0];
}
if (user.user.id === client.user.id) {
return message.channel.send("lol no")
}
if (user.user.id === message.guild.owner.id) {
return message.channel.send("<:error:466995152976871434> You can't kick the owner!")
}
let moderator = message.guild.member(message.author)
if (user.highestRole.position >= moderator.highestRole.position && moderator.user.id !== message.guild.ownerID) {
return message.channel.send(
`<:error:466995152976871434> You can't kick people higher ranked than yourself!`
);
}
let bot = message.guild.member(client.user)
if (user.highestRole.position >= bot.highestRole.position) {
return message.channel.send(
`<:error:466995152976871434> I can't kick people who are higher ranked than me!`
);
}
if (!user.bannable)
return message.channel.send(
"<:error:466995152976871434> Specified user is not bannable."
);
let reason = args.slice(1).join(" ");
if (!reason) reason = `Kicked by ${message.author.tag}`;
await user.kick(reason).catch(console.error);
message.channel.send(`<:success:466995111885144095> Kicked \`${user.user.tag}\``);
if (settings.modlogsChannel !== "off") {
const channel = message.guild.channels.find(
channel => channel.name === settings.modlogsChannel
);
if (channel) {
let embed = new Discord.RichEmbed();
embed.setColor("#fd0061");
embed.setAuthor("User kicked!", user.user.avatarURL);
embed.setDescription(
` User: ${user.user.tag} (${user.user.id})\n Mod: ${message.author} (${message.author.id})\n Reason: ${reason}`
);
try {
channel.send({ embed });
} catch (err) {
// probably no permissions to send messages/embeds there
};
};
};
};
exports.conf = {
enabled: true,
guildOnly: true,
aliases: [],
permLevel: "Moderator",
requiredPerms: ["KICK_MEMBERS"]
};
exports.help = {
name: "kick",
category: "Moderation",
description: "Kicks specified user.",
usage: "kick [user] <reason>"
};