Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Discord.js ban command

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());
    }
}
Comment

Discord.js ban command

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());
    }
}
Comment

discord.js ban user

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
Comment

discord.js ban command

/*
 			 Need more help? Add me on discord: Dwagon#0069
             				Discord.js ^13.8.1
*/

/*
			 With interaction
*/

if (interaction.member.permissions.has("BAN_MEMBERS")) {
            const user = interaction.options.getUser("user")
            const member = interaction.guild.members.cache.get(user.id) || await interaction.guild.members.fetch(user.id).catch(err => { })

            switch (member.id) {
                case (!member):
                    return interaction.reply({
                        content: "ERROR: Cannot find this user!",
                        ephemeral: true
                    })
                case (interaction.member.id):
                    return interaction.reply({
                        content: "ERROR: You cannot ban yourself!",
                        ephemeral: true
                    })
                case (bot.user.id):
                    return interaction.reply({
                        content: "ERROR: You cannot ban me!",
                        ephemeral: true
                    })
                case (member.roles.highest.position >= interaction.member.roles.highest.position):
                    return interaction.reply({
                        content: "ERROR: I can't ban this user, because he's higher than you!",
                        ephemeral: true
                    })
                case (!member.bannable):
                    return interaction.reply({
                        content: "ERROR: I can't ban this user!",
                        ephemeral: true
                    })
                default:
                    const reason = interaction.options.getString("reason");
                    const admin = interaction.user.tag;

                    await interaction.reply({
                        content: ["``" + member.user.tag + "`` has been banned from the server for ``" + reason + "``"],
                        ephemeral: true
                    })

                    await member.ban({ reason: [reason + " | " + admin] });
                    break;
            }
        } else {
          // If doesn't have permission to ban
            return interaction.reply({
                content: "ERROR: You cannot execute this command!",
                ephemeral: true
            })
        }
    }
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to clear form fields in react after submit 
Javascript :: js regex replace unsafe regex 
Javascript :: get index after pushing value in array in js 
Javascript :: Shorthand for calling functions conditionally 
Javascript :: removing element at index without changing the original array 
Javascript :: mapbox gl js openpopup on a marker 
Javascript :: How to apply CodeMirror in Bootstrap Modal 
Javascript :: node sass how to configure number of spaces 
Javascript :: import multiple packages jsp 
Javascript :: 10.8.1.2. The isPalindrome Function 
Javascript :: how to make a website send form to you 
Javascript :: javascript for sub set 
Javascript :: Stateless/Presentational/Dumb component 
Javascript :: ddd 
Javascript :: delete all properties from an javascript object 
Javascript :: textfield extjs retrinjir a 4 caracteres 
Javascript :: session cookie vs persistent cookie 
Javascript :: uselazyquery refetch from child 
Javascript :: reactvs y axis range 
Javascript :: TypeError: t is not a function React 
Javascript :: javascript once per day 
Javascript :: col flex antd 
Javascript :: bootstrap modal show on page load without jquery 
Javascript :: jquery top 20 function 
Javascript :: javascript update array of objects with reduce site:stackoverflow.com 
Javascript :: veu js vs angular vs react features 
Javascript :: listen to changes in children of div in html 
Javascript :: reprompt for permissions with getUserMedia() after initial denial 
Javascript :: angular resolver for cookie 
Javascript :: react-map-multidimensional-array 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =