简体   繁体   English

禁止命令 discord.js v12

[英]Ban command discord.js v12

I made a ban command in discord.js v12.我在 discord.js v12 中做了一个禁止命令。 However whenever i run the command I get an error.但是,每当我运行命令时,都会出现错误。 Here is my code:这是我的代码:

const Discord = require('discord.js');

module.exports = {
    name: "ban",
    description: "Kicks a member from the server",

    async run (client, message, args) {

        if(!message.member.hasPermission("BAN_MEMBERS")) return message.channel.send('You can\'t use that!')
        if(!message.guild.me.hasPermission("BAN_MEMBERS")) return message.channel.send('I don\'t have the right permissions.')

        const member = message.mentions.members.first() || message.guild.members.cache.get(args[0]);

        if(!args[0]) return message.channel.send('Please specify a user');

        if(!member) return message.channel.send('Can\'t seem to find this user. Sorry \'bout that :/');
        if(!member.bannable) return message.channel.send('This user can\'t be banned. It is either because they are a mod/admin, or their highest role is higher than mine');

        if(member.id === message.author.id) return message.channel.send('Bruh, you can\'t ban yourself!');

        let reason = args.slice(1).join(" ");

        if(!reason) reason = 'Unspecified';

        member.ban(`${reason}`).catch(err => { 
          message.channel.send('Something went wrong')
            console.log(err)
        })

        const banembed = new Discord.MessageEmbed()
        .setTitle('Member Banned')
        .setThumbnail(member.user.displayAvatarURL())
        .addField('User Banned', member)
        .addField('Kicked by', message.author)
        .addField('Reason', reason)
        .setFooter('Time kicked', client.user.displayAvatarURL())
        .setTimestamp()

        message.channel.send(banembed);


    }
}

As I had mentioned earlier I keep getting an error whenever I run code.正如我之前提到的,每当我运行代码时,我都会收到错误消息。 Bit new to coding and I was'nt able to resolve the problem my self.编码有点新,我无法自己解决问题。 Here is the error I recive:这是我收到的错误:

Response: Internal Server Error
    at RequestHandler.execute (/home/runner/Utki-the-bot/node_modules/discord.js/src/rest/RequestHandler.js:158:11)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  code: 500,
  method: 'put',
  path: '/guilds/751424392420130907/bans/155149108183695360'
}

Can you help me out?你能帮我吗? Thanks in advance!提前致谢!

The error is not yours.错误不是你的。 The error maybe is occasioned by Discord servers or by discord.js.错误可能是由 Discord 服务器或 discord.js 引起的。 You can wait until it gets solved.你可以等它解决了。 Maybe some minutes.也许几分钟。

I want show you how i made my ban and temp ban command in discord.js v12我想向你展示我是如何在 discord.js v12 中制作我的禁令和临时禁令命令的

I hope what this code can help you and thanks for read我希望这段代码可以帮助你,感谢阅读

const reasonBan = msg.slice(3)
const msg = message.content.split(" ")
const args = msg.slice(1)

  if (cmd === "bt!ban")
  {
    
    const person = message.mentions.users.first()

    if(message.member.hasPermission("ADMINISTRATOR") || message.member.hasPermission("BAN_MEMBERS"))
    {
      if(args.length === 0)
      {
        embed
          .setAuthor("BAN COMMAND" , client.user.avatarURL())
          .setDescription(`**Tienes que especificar dar los argumentos del comando de la siguiente manera:**
          
          \`bt!ban <usuario> <tiempo> <razón> \` `)
          .setColor("RANDOM")
          .setFooter("Ban Command" , "https://cdn.discordapp.com/emojis/824094234801602590.png?v=1")
        
        return message.channel.send(embed)
      }
      else
      {
        if(!person)
        {
          embed
            .setAuthor("BAN COMMAND" , client.user.avatarURL())
            .setDescription(`**${message.author}, tienes que mencionar a alguien a quién banear.**`)
            .setColor("RANDOM")
            .setFooter("Ban Command" , "https://cdn.discordapp.com/emojis/824094234801602590.png?v=1")
        
          return message.channel.send(embed)
        }
        else
        {
          if(person.id === message.author.id)
          {
            embed
              .setAuthor("BAN COMMAND" , client.user.avatarURL())
              .setDescription(`**${message.author}, No puedes banearte a ti mismo**`)
              .setColor("RANDOM")
              .setFooter("Ban Command" , "https://cdn.discordapp.com/emojis/824094234801602590.png?v=1")
        
            return message.channel.send(embed)
          }
          else if(person.id === message.guild.me.id)
          {
            embed
              .setAuthor("BAN COMMAND" , client.user.avatarURL())
              .setDescription(`**${message.author}, No puedes banearme a mi. >:c**`)
              .setColor("RANDOM")
              .setFooter("Ban Command" , "https://cdn.discordapp.com/emojis/824094234801602590.png?v=1")
        
            return message.channel.send(embed)
          }
          else
          {
            const isBannable = message.guild.member(person)
            

            if(isBannable.bannable)
            {
              try 
              {
                isBannable.ban(
                  {
                  reason: 
                    reasonBan.length === 0 ?
                    "Razón no espeficada":
                    reasonBan.join(" ")
                })
                .then(() => 
                {
                  embed
                    .setAuthor("BAN COMMAND" , client.user.avatarURL())
                    .setDescription(`**${message.author}, el usuario ${person}, ha sido baneado correctamente.**
                    
                    **Razón : ${reasonBan === 0? "Razón no espeficada" : reasonBan.join(" ")}**
                    **Tiempo: ${args[1]}**`)
                    .setColor("RANDOM")
                    .setFooter("Ban Command" , "https://cdn.discordapp.com/emojis/824094234801602590.png?v=1")
        
                  return message.channel.send(embed).then(() =>
                  {
                    setTimeout(() => {

                      try 
                      {
                        message.guild.fetchBans().then( bans =>
                          {
                            message.guild.members.unban(person)
                          })
                        embed
                          .setAuthor("BAN COMMAND" , client.user.avatarURL())
                          .setDescription(`**${message.author}, el usuario ${person}, ha sido desbaneado correctamente.
                            
                          **Razón : ${reasonBan === 0? "Razón no espeficada" : reasonBan.join(" ")}
                          Tiempo: ${args[1]}**`)
                          .setColor("RANDOM")
                          .setFooter("Ban Command" , "https://cdn.discordapp.com/emojis/824094234801602590.png?v=1")
                
                        return message.channel.send(embed)
                      } 
                      catch (err) 
                      {
                        embed
                          .setAuthor("BAN COMMAND" , client.user.avatarURL())
                          .setDescription(`**${message.author}, Ha ocurrido un error al intentar quitar el ban de ${person}.**`)
                          .setColor("RANDOM")
                          .setFooter("Ban Command" , "https://cdn.discordapp.com/emojis/824094234801602590.png?v=1")
                
                        return message.channel.send(embed)
                      }
                    }, ms(args[1]))
                  })
                })
              } 
              catch (error) 
              {
                isBannable.ban(
                  {
                    reason: 
                      reasonBan.length === 0 ?
                      "Razón no espeficada":
                      reasonBan.join(" ")
                  }
                )
                .then(() => 
                {
                  embed
                    .setAuthor("BAN COMMAND" , client.user.avatarURL())
                    .setDescription(`**${message.author}, el usuario ${person}, ha sido baneado correctamente.**
                    
                    **Razón: ${reasonBan === 0? "Razón no espeficada" : reasonBan.join(" ")}**`)
                    .setColor("RANDOM")
                    .setFooter("Ban Command" , "https://cdn.discordapp.com/emojis/824094234801602590.png?v=1")
        
                  return message.channel.send(embed)
                })
              }
            }
            else
            {
              embed
                .setAuthor("BAN COMMAND" , client.user.avatarURL())
                .setDescription(`**${message.author}, el usuario tiene más permisos que yo o no está en el server.**`)
                .setColor("RANDOM")
                .setFooter("Ban Command" , "https://cdn.discordapp.com/emojis/824094234801602590.png?v=1")
        
              return message.channel.send(embed)
            }
          }
        }
      }
    }
    else
    {
      embed
        .setAuthor("BAN COMMAND" , client.user.avatarURL())
        .setDescription(`${message.author} ,No tienes permisos para ejecutar este comando.`)
        .setColor("RANDOM")
        .setFooter("Ban Command" , "https://cdn.discordapp.com/emojis/824094234801602590.png?v=1")
    
      return message.channel.send(embed) 
    }
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM