Discord.js ban command

// Import the discord.js module
const Discord = require('discord.js');

// Create an instance of a Discord client
const client = new Discord.Client();

/**
 * The ready event is vital, it means that only _after_ this will your bot start reacting to information
 * received from Discord
 */
client.on('ready', () => {
  console.log('I am ready!');
});

client.on('message', message => {
  // Ignore messages that aren't from a guild
  if (!message.guild) return;

  // if the message content starts with "!ban"
  if (message.content.startsWith('!ban')) {
    // Assuming we mention someone in the message, this will return the user
    // Read more about mentions over at https://discord.js.org/#/docs/main/master/class/MessageMentions
    const user = message.mentions.users.first();
    // If we have a user mentioned
    if (user) {
      // Now we get the member from the user
      const member = message.guild.members.resolve(user);
      // If the member is in the guild
      if (member) {
        /**
         * Ban the member
         * Make sure you run this on a member, not a user!
         * There are big differences between a user and a member
         * Read more about what ban options there are over at
         * https://discord.js.org/#/docs/main/master/class/GuildMember?scrollTo=ban
         */
        member
          .ban({
            reason: 'They were bad!',
          })
          .then(() => {
            // We let the message author know we were able to ban the person
            message.channel.send(`Successfully banned ${user.tag}`);
          })
          .catch(err => {
            // An error happened
            // This is generally due to the bot not being able to ban the member,
            // either due to missing permissions or role hierarchy
            message.channel.send('I was unable to ban the member');
            // Log the error
            console.error(err);
          });
      } else {
        // The mentioned user isn't in this guild
        message.channel.send("That user isn't in this guild!");
      }
    } else {
      // Otherwise, if no user was mentioned
      message.channel.send("You didn't mention the user to ban!");
    }
  }
});

// Log our bot in using the token from https://discord.com/developers/applications
client.login('your token here');

4.4
5
Seika 75 points

                                    let member = message.mentions.members.first();
if(!member) return message.reply("Please mention a valid member of this server");
if(!member.bannable) return message.reply("I cannot ban this member!");

member.ban(); //.ban(reason) if you would to put in the reason through arguments

4.4 (5 Votes)
0
4
5
Phaser 115 points

                                    if (msg.member.hasPermission("BAN_MEMBERS")) {
    if (msg.members.mentions.first()) {
        try {
            msg.members.mentions.first().ban();
        } catch {
            msg.reply("I do not have permissions to ban" + msg.members.mentions.first());
        }
    } else {
        msg.reply("You do not have permissions to ban" + msg.members.mentions.first());
    }
}

4 (5 Votes)
0
4.2
5

                                    //This is the command but you need the kcik command

if (message.content.startsWith("d!kick")) {if (message.member.hasPermission("KICK_MEMBERS")) {
let member = message.mentions.members.first()
if (!member) message.channel.send("Please mention someone")
  else {member.kick().then(mem => {message.channel.send(`Kicked ${mem.user.username}!`)
})}} 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) {
member

4.2 (5 Votes)
0
4.1
10
FuzzyWuzzy 105 points

                                    if (msg.member.hasPermission("KICK_MEMBERS")) {
    if (msg.members.mentions.first()) {
        try {
            msg.members.mentions.first().kick();
        } catch {
            msg.reply("I do not have permissions to kick " + msg.members.mentions.first());
        }
    } else {
        msg.reply("You do not have permissions to kick " + msg.members.mentions.first());
    }
}

4.1 (10 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
discord.js ban with user id how to make a ban commadn in discord.js how make ban command use id discord.js Discord JS Ban id and Kick Command Discord JS Ban and Kick Command how you make ban command with id discord.js how to get the reason for ban discordjs .ban discord js discord.js ban with reason discord.js ban code nodejs discord ban command kick and ban code discord.js ban code discord.js discord.js ban member discord.js ban appeal discord.js kick or ban member command discord js ban by id ban command with time discord.js discord.js ban members ban someone discord js discord.js ban command with reason command handler member.ban() discord js ban & kick Discord.js discord js ban people codelyon ban command discord.js discord .js ban dsicord bot js ban user discord.js ban count discord.js banlist reason command discord.js banlist command reason discord.js banlist command ban members discord.js database bans discord.js ban kiock command discord.js discord js list bans discord js bans discord js uknown ban how to create a ban command in discord.js how to create a ban command in discord.js\ ban user via user id discord.js discord.js how to ban discord js ban member how to make ban command discord.js ban members with one command discord.js ban users discord.js ban code discord-js discord bot ban log discord.js discord js ban global ban command discord.js making a ban command discord.js how to ban discord.js ban user discord.js discord ban bot discordjs discordjs ban command ban user id discordjs how to make a simple ban command in discord.js discord.js listen for bans ban command discord.js with id discord js ban event ban reason discord js discord js ban using id discord.js ban everyone discord.js ban everyone command discord.js ban all discord.js ban command with reason discord.js member.banable ban and kick command discord.js member.ban discord.js simple ban command for discord.js discord.js check ban command how to make kick and ban command in discord.js ban someone with reason discord.js get all bans discord.js ban command with reason discord.js ban all command discord.js ban en discord.js discord.js ban a user discord.js ban user by id ban code in discord.js discord.js how to ban a member ban command wjith reason discor js ban command with reason discord js how to get ban reason discord.js event discord js ban ban member discord js ban discord js discord.js ban plyer ban discord.js discordjs ban member discord js member.ban ban command discordjs.guid ban command discord js ban command discodr.js ban user discord js discord.js kick and ban commands ban command discord.jks ban list discord.js ban ban system discord js discord js ban / kick ban user with id discord.js ban user with id discord.j discord.js ban command v12 ban source code discord.js ban id discord.js ban user from discord server discord.js ban command discord.js v12 with command handle ban command discord.js v12 discord.js user ban discord ban all js discord.js ban person with mention or id discord.js ban a user that is not in the server ban everyone discord.js how to get all bans discord.js kick and ban command mee6 discord.js see bans discord js how to ban a user discord.js user.ban() discord.js kick and ban command discord.js how to ban user discord js Ban command for discord.js 2021 différente permissions kick member discord.js ban member api discord.js bot discord.js kick someone java discord bot ban user discord js how to kick ban discord.js official discord js .kick function discord.js ban everyone without a role Ban logger discord js how to get discord bot to ban playyers how to @ ban member discord js how to @ banned membver discord js how to ban member discord js discord js ban user discord bot kick command js how to make a kick command discord.js how to create a ban command discord.js ban event discord.js discord js .ban() discord js ban command basic discord.js kick command commande ban discord js create a discord bot that banned people discord.js ban command kick bot discord v12 how to ban and uin ban using disxcord.js ban command discord.js copy discord.js ban command work only once how to ban someone discord.js how to ban a user discord js @someone command discord.js ban with reason discord.js how to ban users discord js ban command discord.js banable discord js dsicord.js ban and remove message mentions ban message author discordjs discord.js ban an user that left how to make ban discord.js discord.js kick command discord kick command ban member discord.js discord.js ban command ban.js discord kick comd kick command discord.js bot ban duration discord js how to make a ban command in discord.js discord bot ban command js discord.js ban options discord.js ban keep messages discord.js ban user discord.js how to kick member discord js kick command discord.js ban by id kick commmand discord.js discord.js kick member Discord.js ban command
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source