Rashwan-

Ban command

Mar 23rd, 2020
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const args = message.content.split(' ').slice(1); // All arguments behind the command name with the prefix
  2. const Discord = require('discord.js')
  3.  
  4. const user = message.mentions.users.first(); // returns the user object if an user mention exists
  5. const banReason = args.slice(1).join(' '); // Reason of the ban (Everything behind the mention)
  6. // Check if an user mention exists in this message
  7. if (!user) {
  8. try {
  9. // Check if a valid userID has been entered instead of a Discord user mention
  10. if (!message.guild.members.get(args.slice(0, 1).join(' '))) throw new Error('Couldn\' get a Discord user with this userID!');
  11. // If the client (bot) can get a user with this userID, it overwrites the current user variable to the user object that the client fetched
  12. user = message.guild.members.get(args.slice(0, 1).join(' '));
  13. user = user.user;
  14. } catch (error) {
  15. return message.reply('Couldn\' get a Discord user with this userID!');
  16. }
  17. }
  18. if (user === message.author) return message.channel.send('You can\'t ban yourself'); // Check if the user mention or the entered userID is the message author himsmelf
  19. if (!reason) return message.reply('You forgot to enter a reason for this ban!'); // Check if a reason has been given by the message author
  20. if (!message.guild.member(user).bannable) return message.reply('You can\'t ban this user because you the bot has not sufficient permissions!'); // Check if the user is bannable with the bot's permissions
  21. await message.guild.ban(user) // Bans the user
  22. const banConfirmationEmbed = new Discord.RichEmbed()
  23. .setColor('RED')
  24. .setDescription(`✅ ${user.tag} has been successfully banned!`);
  25. message.channel.send({
  26. embed: banConfirmationEmbed
  27. }); // Sends a confirmation embed that the user has been successfully banned
Add Comment
Please, Sign In to add comment