Skip to content

Update ban.js #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 0 additions & 95 deletions Ep_12/commands/moderation/ban.js
Original file line number Diff line number Diff line change
@@ -1,96 +1 @@
const { RichEmbed } = require("discord.js");
const { stripIndents } = require("common-tags");
const { promptMessage } = require("../../functions.js");

module.exports = {
name: "ban",
category: "moderation",
description: "bans the member",
usage: "<id | mention>",
run: async (client, message, args) => {
const logChannel = message.guild.channels.find(c => c.name === "logs") || message.channel;

if (message.deletable) message.delete();

// No args
if (!args[0]) {
return message.reply("Please provide a person to ban.")
.then(m => m.delete(5000));
}

// No reason
if (!args[1]) {
return message.reply("Please provide a reason to ban.")
.then(m => m.delete(5000));
}

// No author permissions
if (!message.member.hasPermission("BAN_MEMBERS")) {
return message.reply("❌ You do not have permissions to ban members. Please contact a staff member")
.then(m => m.delete(5000));

}
// No bot permissions
if (!message.guild.me.hasPermission("BAN_MEMBERS")) {
return message.reply("❌ I do not have permissions to ban members. Please contact a staff member")
.then(m => m.delete(5000));
}

const toBan = message.mentions.members.first() || message.guild.members.get(args[0]);

// No member found
if (!toBan) {
return message.reply("Couldn't find that member, try again")
.then(m => m.delete(5000));
}

// Can't ban urself
if (toBan.id === message.author.id) {
return message.reply("You can't ban yourself...")
.then(m => m.delete(5000));
}

// Check if the user's banable
if (!toBan.bannable) {
return message.reply("I can't ban that person due to role hierarchy, I suppose.")
.then(m => m.delete(5000));
}

const embed = new RichEmbed()
.setColor("#ff0000")
.setThumbnail(toBan.user.displayAvatarURL)
.setFooter(message.member.displayName, message.author.displayAvatarURL)
.setTimestamp()
.setDescription(stripIndents`**- baned member:** ${toBan} (${toBan.id})
**- baned by:** ${message.member} (${message.member.id})
**- Reason:** ${args.slice(1).join(" ")}`);

const promptEmbed = new RichEmbed()
.setColor("GREEN")
.setAuthor(`This verification becomes invalid after 30s.`)
.setDescription(`Do you want to ban ${toBan}?`)

// Send the message
await message.channel.send(promptEmbed).then(async msg => {
// Await the reactions and the reactioncollector
const emoji = await promptMessage(msg, message.author, 30, ["✅", "❌"]);

// Verification stuffs
if (emoji === "✅") {
msg.delete();

toBan.ban(args.slice(1).join(" "))
.catch(err => {
if (err) return message.channel.send(`Well.... the ban didn't work out. Here's the error ${err}`)
});

logChannel.send(embed);
} else if (emoji === "❌") {
msg.delete();

message.reply(`ban canceled.`)
.then(m => m.delete(10000));
}
});
}
};