discord.js ban v12 code example
Example 1: unban command discord.js v12
if(command === "unban"){
if(!msg.member.hasPermission("BAN_MEMBERS")) {
return msg.channel.send(`**${msg.author.username}**, You do not have perms to unban someone`)
}
if(!msg.guild.me.hasPermission("BAN_MEMBERS")) {
return msg.channel.send(`**${msg.author.username}**, I do not have perms to unban someone`)
}
let userID = args[0]
msg.guild.fetchBans().then(bans=> {
if(bans.size == 0) return
let bUser = bans.find(b => b.user.id == userID)
if(!bUser) return
msg.guild.members.unban(bUser.user)
})
;}
Example 2: discord.js v12 command ban
if (!message.member.hasPermission("BAN_MEMBERS")) return message.channel.send("Invalid Permissions")
let User = message.guild.member(message.mentions.users.first()) || message.guild.members.get(args[0])
if (!User) return message.channel.send("Invalid User")
if (User.hasPermission("BAN_MEMBERS")) return message.reply("Invalid Permissions")
let banReason = args.join(" ").slice(22);
if (!banReason) {
banReason = "None"
}
User.ban({reason: banReason})