Files
xiao/commands/moderation/kick.js
T
Daniel Odendahl Jr 7c0a39ec5c return and await
2017-03-23 13:16:59 +00:00

58 lines
2.8 KiB
JavaScript

const commando = require('discord.js-commando');
const Discord = require('discord.js');
module.exports = class KickCommand extends commando.Command {
constructor(Client) {
super(Client, {
name: 'kick',
group: 'moderation',
memberName: 'kick',
description: 'Kicks a user. (;kick @User being a jerk.)',
examples: [";kick @User being a jerk."]
});
}
async run(message) {
if (message.channel.type !== 'dm') {
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES', 'EMBED_LINKS', 'KICK_MEMBERS'])) return;
}
console.log(`[Command] ${message.content}`);
if (message.channel.type !== 'dm') {
let userToKick = message.mentions.users.first();
let reason = message.content.split(" ").slice(2).join(" ");
if (message.mentions.users.size !== 1) {
return message.channel.send(":x: Error! Please mention one user!");
}
else {
if (message.member.hasPermission('KICK_MEMBERS')) {
if (message.guild.member(userToKick).kickable) {
await message.channel.send(":ok_hand:");
await message.guild.member(userToKick).kick();
if (message.guild.channels.exists("name", "mod_logs")) {
const embed = new Discord.RichEmbed()
.setAuthor(`${message.author.username}#${message.author.discriminator}`, message.author.avatarURL)
.setColor(0xFFA500)
.setFooter('XiaoBot Moderation', this.client.user.avatarURL)
.setTimestamp()
.setDescription(`**Member:** ${userToKick.username}#${userToKick.discriminator} (${userToKick.id})\n**Action:** Kick\n**Reason:** ${reason}`);
return message.guild.channels.find('name', 'mod_logs').sendEmbed(embed).catch(console.error);
}
else {
return message.channel.send(":notepad_spiral: **Note: No log will be sent, as there is not a channel named 'mod_logs'. Please create it to use the logging feature.**");
}
}
else {
return message.channel.send(":x: Error! This member cannot be kicked! Perhaps they have a higher role than me?");
}
}
else {
return message.channel.send(":x: Error! You don't have the Kick Members Permission!");
}
}
}
else {
return message.channel.send(":x: Error! This command does not work in DM!");
}
}
};