1// Import the discord.js module
2const Discord = require('discord.js');
3
4// Create an instance of a Discord client
5const client = new Discord.Client();
6
7/**
8 * The ready event is vital, it means that only _after_ this will your bot start reacting to information
9 * received from Discord
10 */
11client.on('ready', () => {
12 console.log('I am ready!');
13});
14
15client.on('message', message => {
16 // Ignore messages that aren't from a guild
17 if (!message.guild) return;
18
19 // if the message content starts with "!ban"
20 if (message.content.startsWith('!ban')) {
21 // Assuming we mention someone in the message, this will return the user
22 // Read more about mentions over at https://discord.js.org/#/docs/main/master/class/MessageMentions
23 const user = message.mentions.users.first();
24 // If we have a user mentioned
25 if (user) {
26 // Now we get the member from the user
27 const member = message.guild.members.resolve(user);
28 // If the member is in the guild
29 if (member) {
30 /**
31 * Ban the member
32 * Make sure you run this on a member, not a user!
33 * There are big differences between a user and a member
34 * Read more about what ban options there are over at
35 * https://discord.js.org/#/docs/main/master/class/GuildMember?scrollTo=ban
36 */
37 member
38 .ban({
39 reason: 'They were bad!',
40 })
41 .then(() => {
42 // We let the message author know we were able to ban the person
43 message.channel.send(`Successfully banned ${user.tag}`);
44 })
45 .catch(err => {
46 // An error happened
47 // This is generally due to the bot not being able to ban the member,
48 // either due to missing permissions or role hierarchy
49 message.channel.send('I was unable to ban the member');
50 // Log the error
51 console.error(err);
52 });
53 } else {
54 // The mentioned user isn't in this guild
55 message.channel.send("That user isn't in this guild!");
56 }
57 } else {
58 // Otherwise, if no user was mentioned
59 message.channel.send("You didn't mention the user to ban!");
60 }
61 }
62});
63
64// Log our bot in using the token from https://discord.com/developers/applications
65client.login('your token here');
1if (msg.member.hasPermission("BAN_MEMBERS")) {
2 if (msg.members.mentions.first()) {
3 try {
4 msg.members.mentions.first().ban();
5 } catch {
6 msg.reply("I do not have permissions to ban" + msg.members.mentions.first());
7 }
8 } else {
9 msg.reply("You do not have permissions to ban" + msg.members.mentions.first());
10 }
11}
12
1let member = message.mentions.members.first();
2if(!member) return message.reply("Please mention a valid member of this server");
3if(!member.bannable) return message.reply("I cannot ban this member!");
4
5member.ban(); //.ban(reason) if you would to put in the reason through arguments
1if (msg.member.hasPermission("KICK_MEMBERS")) {
2 if (msg.members.mentions.first()) {
3 try {
4 msg.members.mentions.first().kick();
5 } catch {
6 msg.reply("I do not have permissions to kick " + msg.members.mentions.first());
7 }
8 } else {
9 msg.reply("You do not have permissions to kick " + msg.members.mentions.first());
10 }
11}
12
1//This is the command but you need the kcik command
2
3if (message.content.startsWith("d!kick")) {if (message.member.hasPermission("KICK_MEMBERS")) {
4let member = message.mentions.members.first()
5if (!member) message.channel.send("Please mention someone")
6 else {member.kick().then(mem => {message.channel.send(`Kicked ${mem.user.username}!`)
7})}} else {message.reply("You don't have the permission to do that...")}} if (message.content.startsWith('d!ban')) {if(message.member.hasPermission("BAN_MEMBERS")) {const user = message.mentions.users.first(); if (user) {const member = message.guild.member(user);if (member) {
8member