Picsou
Picsou

Reputation: 24

Command to ban by mention in discord

Hello I made a ban command, but on the line: I put:

which corresponds to the first mention of the message.

Except that the mention can be anywhere, so I'm looking for how to make the bot detect that the mention is at the beginning or not.

Any help is appreciated.

Thank you for taking the time to read this and I wish you a good day.

module.exports.run = async(client, message, args) => {

const Discord = require("discord.js");
const Breason = message.content.slice(22);
let target = message.mentions.users.first();

if(!message.guild.me.permissionsIn(message.channel.id).has("SEND_MESSAGES")) return;
if(!message.guild.me.permissionsIn(message.channel.id).has("EMBED_LINKS")) return;

if(!message.guild.member(client.user).hasPermission("BAN_MEMBERS")) return message.channel.send("Je n'ai pas la permsission de ban ce membre.")
if(!message.guild.member(message.author).hasPermission("BAN_MEMBERS")) return message.channel.send("Vous n'avez pas la permission de ban")

if(bUser === message.author.id) return message.channel.send("Vous ne pouvez pas vous auto-ban.")

if(!bUser) return message.channel.send("Veuillez mentionnez un utilisateur à bannir.")

if(!Breason) return message.channel.send("Ho ! Il manque une raison, serait ce un abus de privilèges ?:thinkinghard: ")




message.guild.members.ban(bUser, {reason: Breason})

const embed = new Discord.MessageEmbed()

.setColor("RANDOM")
.setTitle("Un membre à été banni !")
.addField("Membre banni :", bUser.tag, true)
.addField("Banni par:", message.author.tag, true)
.addField("Pour la raison:", Breason, true)
.setFooter("Une nouvelle personne a été banni !")
.setTimestamp()

message.channel.send(embed)

bUser.send(embed)
 
 
 };
 module.exports.help = {
 name: "ban",
 aliases: ["Bane", "banne"],
 description: "Ban l'utilisateur mentionner.",
 usage: "ban <user.mention> <raison>"
 
 };

If my explanations are not clear, let me know and I will be happy to correct.

Upvotes: 0

Views: 243

Answers (1)

Theblockbuster1
Theblockbuster1

Reputation: 317

Assuming that args is an array of arguments from message.content (separated by whitespace),

let target = args[0].includes(message.mentions.users.first().id) ? message.mentions.users.first() : null;

Upvotes: 1

Related Questions