Advertisement
ConfonedDev

Discord.js Kick

Feb 25th, 2020
6,715
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require('discord.js');
  2.  
  3. const client = new Discord.Client();
  4.  
  5. const config = require("./config.json");
  6.  
  7.  
  8. client.on('ready', () => {
  9.   console.log('I am ready!');
  10. }); //This is sending a message to the terminal to show the bot is online and working.
  11.  
  12. client.on('message', message => {
  13.  
  14.   if (!message.guild) return;
  15.  
  16.  
  17.   if (message.content.startsWith('?kick')) { //**This is the command, this says if someone says ?kick then pay attention to teh rest to teh bot.**\\
  18.    
  19.     const user = message.mentions.users.first(); // This says if you mention this user, it is talking about that user
  20.    
  21.     if (user) {
  22.    
  23.       const member = message.guild.member(user);
  24.    
  25.       if (member) {
  26.      
  27.         member.kick('Optional reason that will display in the audit logs').then(() => {
  28.        
  29.           message.reply(`Successfully kicked ${user.tag}, you should feel bad! They will never be able to rejoin until they click join again!`);
  30.         }).catch(err => {
  31.          
  32.           message.reply('I was unable to kick the member. Check if their roles are higher then mine or if they have administrative permissions!');
  33.          
  34.           console.error(err);
  35.         });
  36.       } else {
  37.        
  38.         message.reply('That user isn\'t in this guild!');
  39.       }
  40.  
  41.     } else {
  42.       message.reply('You didn\'t mention the user to kick!'); // Thus is creating a message so that you know if you failed
  43. // The / is to show the script that the (') is not the end of it
  44.     }
  45.   }
  46. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement