#banning a discord user from the guild
1 messages · Page 1 of 1 (latest)
I was refactoring your code but I just can't be asked. Here's the banning:
const Discord = require("discord.js");
module.exports = {
name: "ban",
alias: ["b", "banish"],
userPerms: ["BAN_MEMBERS"],
botPerms: ["BAN_MEMBERS"],
async execute(client, message, args) {
const erroricon =
"https://images.emojiterra.com/twitter/v13.1/512px/1f6ab.png";
const infoicon =
"https://images.emojiterra.com/google/android-nougat/512px/2139.png";
const embed1 = new Discord.MessageEmbed()
.setTitle("Error")
.setColor("020202")
.setFooter("La Colonia", erroricon)
.setTimestamp()
.setDescription(`Debes mencionar a un usuario.`);
if (!args[0])
return message.channel.send({
embeds: [embed1],
});
let target =
message.mentions.members.first() ||
message.guild.members.cache.get(args[0]) ||
message.guild.members.cache.find(
(r) => r.user.username.toLowerCase() === args[0].toLocaleLowerCase()
) ||
message.guild.members.cache.find(
(ro) => ro.displayName.toLowerCase() === args[0].toLocaleLowerCase()
);
var reason = args.slice(1).join(" ");
const embed2 = new Discord.MessageEmbed()
.setColor("020202")
.setTitle("Error")
.setFooter("La Colonia", erroricon)
.setTimestamp()
.setDescription(`Ese usuario no existe o no esta en el servidor.`);
if (!target)
return message.channel.send({
embeds: [embed2],
});
const embed3 = new Discord.MessageEmbed()
.setColor("020202")
.setTitle("Error")
.setFooter("La Colonia", erroricon)
.setTimestamp()
.setDescription(`No te puedes banear a ti mismo.`);
if (target === message.member)
return message.channel.send({
embeds: [embed3],
});
const embed4 = new Discord.MessageEmbed()
.setColor("020202")
.setTitle("Error")
.setFooter("La Colonia", erroricon)
.setTimestamp()
.setDescription(`No puedes banear a ese usuario.`);
if (!target.bannable)
return message.channel.send({
embeds: [embed4],
});
try {
const embed5 = new Discord.MessageEmbed()
.setColor("020202")
.setTitle(`Has sido baneado de ${message.guild.name}`)
.setFooter("La Colonia", infoicon)
.setTimestamp()
.addField("Razón:", `${reason || "Sin razón definida"}`)
.addField("Baneado por:", `${message.author}`);
target
.send({
embeds: [embed5],
})
.then(
async () =>
await message.guild.bans.create(target, {
days: 7,
reason: reason,
})
)
.catch(() => null);
} catch {
await message.guild.bans.create(target, {
days: 7,
reason: reason,
});
}
if (reason) {
var embed6 = new Discord.MessageEmbed()
.setColor("020202")
.setTitle(`${target.user.tag} ha sido baneado del servidor`)
.setFooter("La Colonia", infoicon)
.setTimestamp()
.addField("Razón:", `${reason}`)
.addField("Baneado por:", `${message.author}`);
message.channel.send({ embeds: [embed6] });
} else {
var embed7 = new Discord.MessageEmbed()
.setColor("020202")
.setTitle(`${target.user.tag} ha sido baneado del servidor`)
.setFooter("La Colonia", infoicon)
.setTimestamp()
.addField("Razón:", `Sin razón definida`)
.addField("Baneado por:", `${message.author}`);
message.channel.send({ embeds: [embed7] });
}
},
};