discord js ban command

Solutions on MaxInterview for discord js ban command by the best coders in the world

showing results for - "discord js ban command"
Eric
18 Apr 2020
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');
Matilda
05 May 2019
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
Alexander
11 Feb 2016
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
Mia
25 Jan 2020
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
Jordan
28 Nov 2016
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
queries leading to this page
kick commmand discord jsban command discodr jsban all discord js commnadhow to create a ban command in discord js 5cban kiock command discord jsdiscord js ban command with reasonban discord jsban user discord jsban reason discord jsban command using id discord js tsban code discord jsdiscord js ban everyonediscord js how to kickdiscord js index ban commandhow make ban command use id discord jshow to make a kick command discord jshow to 40 banned membver discord jsglobal ban command discord jshow to ban discord jsdiscord js ban everyone commandcommand kick bot discord v12how to get ban reason discord jsdiscord js ban an user that leftcommand ban all discord jsdiscord js ban members that are not on serverdiscord js ban 28 29discord js kick memberban command discord js v12 with command handlediscord js kick membersdiscord js on kickdiscord js bandiscord js ban all usersdiscord js ban command with reason command handlerban members discord jsuser ban 28 29 discord jsdiscord js ban userbasic discord js kick commanddiscord bothow to ban a user discord js kick 28 29 discord jsdiscord js list bansdiscord js ban id and kick commanddiscord js ban command work only oncediscord js ban command templatehow to make a ban command discord jscodelyon ban command discord jsmaking a ban command discord jsdiscord js ban with reasonget all bans discord jsdiscord js ban all membersjavascript how to make ban command discord jssee bans discord jsdiscord bot kick command jsban commajnd discord jsdiscord js ban commandban reason discord jsdiscord js ban user by iddiscord js ban eventban member discord jsban command discord js copyban discord js officialdsicord bot js ban userban message author discordjsban command discord jksdiscord js banlist reason command ban user discord jsdiscord js kick functionhow to create a ban list in discord jsnode js discord banban command wjith reason discor js message ban dsicord jsban code discord jsban members with one command discord jskick command discord js botdiscord js how to kick memberban ban system discord jsdiscord js kick and ban commandsban command discord js v12ban everyone discord jsdiscord js ban memberdiscord js ban a user that is not in the serverban discord jsdiscord mass ban command jshow to ban member discord jsdiscord js ban keep messagesban command with reason discord jsban list discord jshow to ban a user discord jsban all discord jsdiscord js ban optionsban code in discord jsdiscord js ban by iddiscord js uknown bandiscord js ban command v12ban time discord jsdiscord js ban person with mention or idevent discord js banban all users discord jsdiscord js member banableban id discord jsdiff c3 a9rente permissions kick member discord jsdiscord js ban appealdiscord js ban memberhow to code a ban command in discord jskick discord jsban user with id discord jkick and ban code discord jsban member api discord js botban user with id discord jsban user from discord server discord jsban command discord jsdiscord js bankick discord js by id discord js ban memberscreate a discord bot that banned peoplecommande ban discord jshow to get the reason for ban discordjsban user discord js v12ban someone with reason discord jsdiscordjs ban memberhow to get discord bot to ban playyersnodejs discord ban commanddiscord js ban commandban command discord jshow you make ban command with id discord jskick and ban command discord jsdiscord js basic bandiscord js banshow to create a ban command in discord jshow to ban a user from using your bot discord jsdiscord ban bot discordjsdiscord js banlist command reasonban and kick command discord jsdiscord js ban countban all command discord jsdiscord js ban and unban codediscord js kickhow to make ban discord jskick command discord jshow to ban and uin ban using disxcord jshow to make a ban command in discord jsdiscord ban user jsdiscord js ban with user idhow to make ban command discord jshow to create a ban command discord jsdiscord js ban and kick cmdban logger discord jsdiscord js kick or ban member commandban user id discordjsban en discord jsdiscord js ban using idban 26 kick discord jsmember ban 28 29 discord jsban member discord jsban and kick using id discord jshow to ban someone discord jsban event discord jsdiscordjs ban commandhow to maek a kick command in discord jsdiscord js kick commandban log discord jssimple ban command for discord jsban command discordjs guiddiscord js ban and kick commandban command with time discord jsdiscord js ban userdiscord ban all jsdiscord js ban command ban jsdsicord js ban and remove message mentionshow to make kick and ban command in discord jsdiscord js ban and kick commanddiscord js ban by idmember ban discord jsdiscord js ban a userdiscord js org banban user via user id discord jsjava discord bot ban userban user discord js v1how to ban user discord jsdiscord js member banhow to use ids for bans discord jsdiscord js user bandatabase bans discord jsban command with reason discord jsban command discord js with idban duration discord jsdiscord bot ban command jshow to make a ban command in discord js rconxhow to make a ban commadn in discord js ban discord jsdiscord js banhow to make a simple ban command in discord jsdiscord js kick commanddiscord js ban everyone without a rolehow to 40 ban member discord jsdiscord js kick command with permissionsdiscord js banlist commandban someone discord jsdiscord js how to ban a memberban users discord jsbanable discord jshow to get all bans discord jsdiscord js listen for bansview ban reason discord jsban source code discord jsdiscord js ban reasondiscord js kick someonediscord js ban plyerhow to ban users discord js 40someone command discord jsdiscord js ban alldiscord js how to bandiscord js ban peoplediscord js ban 2f kickban command for discord js 2021kick and ban command mee6 discord jsban with reason discord jsdiscord js check ban commanddiscord js ban codediscord js ban command