{ if (message.member.hasPermission(["KICK_MEMBERS", "BAN_MEMBERS"])) { if (message.content.startsWith(`${prefix}kick" /> { if (message.member.hasPermission(["KICK_MEMBERS", "BAN_MEMBERS"])) { if (message.content.startsWith(`${prefix}kick" /> { if (message.member.hasPermission(["KICK_MEMBERS", "BAN_MEMBERS"])) { if (message.content.startsWith(`${prefix}kick"/>

I need help I am trying to put a kick and ban command inside the code but I don't know where I need put it

56 views Asked by At
 client.on("message", (message) => {
if (message.member.hasPermission(["KICK_MEMBERS", "BAN_MEMBERS"])) {
    if (message.content.startsWith(`${prefix}kick`)) {
      let member = message.mentions.members.first();
      if(!member) return message.channel.send('Cannot find this member');
      member.kick().then((member) => {
        message.channel.send("```" + member.displayName + " has been kicked ```");
      });
    }
  }

This is the code of kick and ban.^^

  1. https://sourceb.in/2e6ba31dc3 - this is my discord bot code where I want to put the ban and kick command code
1

There are 1 answers

0
DskField On BEST ANSWER

You want to put the command inside of the client.on("message", (message) block. I'll use it in your code as an example:

client.on('message', message =>{
    if(!message.content.startsWith(prefix) || message.author.bot) return;
 
    const args = message.content.slice(prefix.length).split(/ +/);
    const command = args.shift().toLowerCase();
 
    if(command === 'ping'){
        client.commands.get('ping').execute(message, args);
    }
    
    // Kick start
    if (command === 'kick') {

      // Only check if the command caller has permission,
      // AFTER the command is called, not before.
      if (message.member.hasPermission(["KICK_MEMBERS", "BAN_MEMBERS"])) {

        // Define which member needs to get kicked by grabbing the first mentioned guild member
        let member = message.mentions.members.first();

        // If the tagged member is not found in your guild,
        // throw this message
        if(!member) return message.channel.send('Cannot find this member');

        // Proceed to kick the member
        member.kick().then((member) => {
          message.channel.send("```" + member.displayName + " has been kicked ```");
      });
    }

});

I hope this answers your question. Check the discordjs docs here if you haven't checked them already. They feature a nice tutorial on setting up your bot.