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 ban extends command {
|
|
|
|
constructor() {
|
|
|
|
// Set execution method, description, category, and usage
|
|
|
|
super("ban");
|
|
|
|
super.description = "Bans the mentioned user with an optional reason";
|
|
|
|
super.category = "Moderation";
|
|
|
|
super.usage = "<@user> [reason]";
|
|
|
|
|
|
|
|
// Set required configs in the config.ban json string
|
|
|
|
super.requiredConfigs = "modrole";
|
|
|
|
super.requiredCofigs = "logchannel";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Command execution method
|
|
|
|
ban(context) {
|
|
|
|
// If the user has the modrole (set in config.ban.modrole)
|
|
|
|
if (context.message.guild.roles.cache.find(role => role.name == context.client.config.ban.modrole)) {
|
|
|
|
// Gets the 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 the user pinged is a valid user
|
|
|
|
if (user) {
|
|
|
|
// Get the guild member object from 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 they are in the server
|
|
|
|
if (member) {
|
|
|
|
// Get the arguments and remove what isn't 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);
|
|
|
|
|
|
|
|
// Join the array 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 guild is available to work with
|
|
|
|
if (context.message.guild.available) {
|
|
|
|
// If the bot client is able to ban the member
|
|
|
|
if (member.bannable) {
|
|
|
|
// The Message Embed which goes 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 Banned")
|
|
|
|
.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 Message Embed which goes into the public channel the message 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 banned`);
|
|
|
|
|
|
|
|
// Ban the member and send the embeds into the appropriate channel, then delete the initial message
|
|
|
|
member.ban({ reason: reason }).then(() => {
|
|
|
|
context.message.guild.channels.cache.find(channel => channel.name == context.client.config.ban.logchannel).send(embedLog);
|
|
|
|
context.message.channel.send(embedPublic);
|
|
|
|
|
|
|
|
context.message.delete();
|
|
|
|
}).catch(err => { // If the bot couldn't ban the member, say so and log the error to the console
|
|
|
|
errorEmbed(context, "An error occurred");
|
|
|
|
console.log(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { // If the member object doesn't exist
|
|
|
|
errorEmbed(context, "User is not in this server");
|
|
|
|
}
|
|
|
|
} else { // If the user object doesn't exist
|
|
|
|
errorEmbed(context, "User does not exist");
|
|
|
|
}
|
|
|
|
} else { // If the user doesn't have the mod role
|
|
|
|
errorEmbed(context, `You require the \`${context.client.config.ban.modrole}\` role to run this command`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Post an error embed
|
|
|
|
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 = ban;
|