2020-11-01 19:29:12 +00:00
|
|
|
// Required Components
|
|
|
|
const { command } = require('vylbot-core');
|
|
|
|
const { MessageEmbed } = require('discord.js');
|
|
|
|
|
|
|
|
const embedColor = "0x3050ba";
|
|
|
|
|
|
|
|
// Command Class
|
|
|
|
class kick extends command {
|
|
|
|
constructor() {
|
|
|
|
// Sets the command's run method, description, category, and usage
|
|
|
|
super("kick");
|
|
|
|
super.description = "Kicks the mentioned user with an optional reason";
|
|
|
|
super.category = "Moderation";
|
|
|
|
super.usage = "<@user> [reason]";
|
|
|
|
|
|
|
|
// Sets the required configs for the command
|
|
|
|
super.requiredConfigs = "modrole";
|
|
|
|
super.requiredConfigs = "logchannel";
|
|
|
|
}
|
|
|
|
|
|
|
|
// The command's run method
|
|
|
|
kick(context) {
|
|
|
|
// Checks if the user has the mod role, set in the config json string
|
|
|
|
if (context.message.member.roles.cache.find(role => role.name == context.client.config.kick.modrole)) {
|
|
|
|
// Gets the first user pinged in the command
|
2021-02-17 18:12:45 +00:00
|
|
|
const user = context.message.mentions.users.first();
|
2020-11-01 19:29:12 +00:00
|
|
|
|
|
|
|
// If a user was pinged
|
|
|
|
if (user) {
|
|
|
|
// Gets the guild member object of the pinged user
|
2021-02-17 18:12:45 +00:00
|
|
|
const member = context.message.guild.member(user);
|
2020-11-01 19:29:12 +00:00
|
|
|
|
|
|
|
// If the member object exists, i.e if the user is in the server
|
|
|
|
if (member) {
|
|
|
|
// Gets the part of the argument array which holds the reason
|
2021-02-17 18:12:45 +00:00
|
|
|
const reasonArgs = context.arguments;
|
2020-11-01 19:29:12 +00:00
|
|
|
reasonArgs.splice(0, 1);
|
|
|
|
|
|
|
|
// Joins the reason into a string
|
2021-02-17 18:12:45 +00:00
|
|
|
const reason = reasonArgs.join(" ");
|
2020-11-01 19:29:12 +00:00
|
|
|
|
|
|
|
// If the server is available
|
|
|
|
if (context.message.guild.available) {
|
|
|
|
// If the bot client can kick the mentioned member
|
|
|
|
if (member.kickable) {
|
|
|
|
// The embed to go into the bot log
|
2021-02-17 18:12:45 +00:00
|
|
|
const embedLog = new MessageEmbed()
|
2020-11-01 19:29:12 +00:00
|
|
|
.setTitle("Member Kicked")
|
|
|
|
.setColor(embedColor)
|
|
|
|
.addField("User", `${user} \`${user.tag}\``, true)
|
|
|
|
.addField("Moderator", `${context.message.author} \`${context.message.author.tag}\``, true)
|
|
|
|
.addField("Reason", reason || "*none*")
|
|
|
|
.setThumbnail(user.displayAvatarURL);
|
|
|
|
|
|
|
|
// The embed to go into channel the command was sent in
|
2021-02-17 18:12:45 +00:00
|
|
|
const embedPublic = new MessageEmbed()
|
2020-11-01 19:29:12 +00:00
|
|
|
.setColor(embedColor)
|
|
|
|
.setDescription(`${user} has been kicked`);
|
|
|
|
|
|
|
|
// Attemtp to kick the user, if successful send the embeds, if unsuccessful notify the chat and log the error
|
|
|
|
member.kick({ reason: reason }).then(() => {
|
|
|
|
context.message.guild.channels.cache.find(channel => channel.name == context.client.config.kick.logchannel).send(embedLog);
|
|
|
|
context.message.channel.send(embedPublic);
|
|
|
|
|
|
|
|
context.message.delete();
|
|
|
|
}).catch(err => {
|
|
|
|
errorEmbed(context, "An error has occurred");
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
} else { // If the user isn't kickable
|
|
|
|
errorEmbed(context, "I am unable to kick this user");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { // If the member object is invalid
|
|
|
|
errorEmbed(context, "Please specify a valid user");
|
|
|
|
}
|
|
|
|
} else { // If the user object is invalid
|
|
|
|
errorEmbed(context, "Please specify a valid user");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function to post an embed in case of an error
|
|
|
|
function errorEmbed(context, message) {
|
2021-02-17 18:12:45 +00:00
|
|
|
const embed = new MessageEmbed()
|
2020-11-01 19:29:12 +00:00
|
|
|
.setColor(embedColor)
|
|
|
|
.setDescription(message);
|
|
|
|
|
|
|
|
context.message.channel.send(embed);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = kick;
|