kick.js

mail@pastecode.io avatar
unknown
javascript
3 years ago
4.8 kB
3
Indexable
Never
const { MessageEmbed } = require("discord.js");
const { prefix } = require('../../config.json');

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

  try {
  
  if (!message.member.guild.me.hasPermission('KICK_MEMBERS')) {
		const errors = new MessageEmbed()
			.setColor('#f95cff')
			.setAuthor(
				`Error detected [ Console Log ]`,
				`https://cdn.discordapp.com/emojis/786538253591117875.gif`
			)
			.setDescription(
				'Below are the errors that i found\n**```\n' +
					`I don't have KICK MEMBERS permission(s) to execute this commands, please contact server admin to give me permission(s)!!` +
					'\n```**'
			)
			.setFooter(`${message.client.user.username} - ${client.config.server}`);

		await message.channel.send(errors).then(m => m.delete({ timeout: 15000 }));
		return message.delete();
	}

	if (!message.member.hasPermission('KICK_MEMBERS')) {
		const errors = new MessageEmbed()
			.setColor('#f95cff')
			.setAuthor(
				`Error detected [ Console Log ]`,
				`https://cdn.discordapp.com/emojis/786538253591117875.gif`
			)
			.setDescription(
				'Below are the errors that i found\n**```\n' +
					`You don't have KICK MEMBERS permission(s) to execute this commands!!` +
					'\n```**'
			)
			.setFooter(`${message.client.user.username} - ${client.config.server}`);

		await message.channel.send(errors).then(m => m.delete({ timeout: 15000 }));
		return message.delete();
	}
	
	let User = message.guild.member(message.mentions.members.first()) || message.guild.members.cache.get(args[0])
  
  if (!User) {
    const nouser = new MessageEmbed()
      .setColor('#f95cff')
			.setAuthor(`Error detected [ Missing Arguments ]`,
				`https://cdn.discordapp.com/emojis/786538253591117875.gif`)
			.setDescription('Below are the errors that i found\n**```\n' +
					`Please tag or give me ID of the user in this server that you want to kick!!` +
					'\n```**')
			.setFooter(`${message.client.user.username} - ${client.config.server}`);

    await message.channel.send(nouser).then(m => m.delete({ timeout: 10000 }));
    return message.delete();
  }
  
  if (User.hasPermission("KICK_MEMBERS")) {
    const cant = new MessageEmbed()
      .setColor('#f95cff')
			.setAuthor(`Error detected [ Missing Arguments ]`,
				`https://cdn.discordapp.com/emojis/786538253591117875.gif`)
			.setDescription('Below are the errors that i found\n**```\n' +
					`I can't kick that user, do they have higger role than me??` +
					'\n```**')
			.setFooter(`${message.client.user.username} - ${client.config.server}`);

    await message.channel.send(cant).then(m => m.delete({ timeout: 10000 }));
    return message.delete();
  }
  
  else {
    
    let kickReason = args.join(" ").slice(22);
    if (!kickReason) {
      kickReason = "No Reason"
    }
    
    const getkick = new MessageEmbed()
		.setAuthor(`Member Kicked`,
				`https://cdn.discordapp.com/emojis/805741376910131210.gif`)
    .setDescription(`<a:HL_yes:792344238901690369> **Successfully** kicked **${User} (${User.id})** for reason **${kickReason}**`)
    .setColor('#f95cff')
    .setTimestamp()
    .setFooter(`${message.client.user.username}`);

   User.kick(kickReason)
   var UserID = User.id
   console.log(`Kicked ${User} (${UserID}) from ${message.guild.name}`)
   
   const getkick2 = new MessageEmbed()
		.setAuthor(`Member Kicked`,
				`https://cdn.discordapp.com/emojis/805741376910131210.gif`)
    .setDescription(`You have been kicked from **${message.guild.name}**\nReason : ${kickReason}`)
    .setColor('#f95cff')
    .setTimestamp()
    .setFooter(`${message.client.user.username} - ${client.config.server}`);

   await message.channel.send(getkick)
   await User.send(getkick2)
   return message.delete()
    
    
  }
  
  } catch (error) {
    
    console.error(error);
    const errors = new MessageEmbed()
      .setColor('#f95cff')
      .setAuthor(`Error detected [ Console Log ]`, `https://cdn.discordapp.com/emojis/786538253591117875.gif`)
      .setDescription("Below are the errors that i found\n\n**```\n" + error + "\n```**\nPlease contact " + `**[Kang Dittyaa](${client.config.inviteserver})**`)
      .setFooter(`${message.client.user.username} - ${client.config.server}`);
        
    await message.channel.send(errors).then(m => m.delete({ timeout: 15000 }));
    return message.delete();
    
  }
};

exports.help = {
  name: "kick",
  description: "Kick a user from a server",
  usage: `${prefix}kick <Tag User> [Reason]`,
  example: `• ${prefix}kick @Kang Dittyaa#190 Scammer\n• ${prefix}kick 723092028396797982 Scammer`
};

exports.conf = {
  aliases: [],
  cooldown: 20 // This number is a seconds, not a milliseconds.
  // 1 = 1 seconds.
}