【问题标题】:Ban command discord.js v12禁止命令 discord.js v12
【发布时间】:2021-07-02 20:10:42
【问题描述】:

我在 discord.js v12 中做了一个禁止命令。但是,每当我运行命令时,都会出现错误。这是我的代码:

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);


    }
}

正如我之前提到的,每当我运行代码时,我都会不断收到错误消息。对编码有点陌生,我无法自己解决问题。这是我收到的错误:

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'
}

你能帮帮我吗?提前致谢!

【问题讨论】:

  • 这是您执行命令的 Discord 服务器的错误,而不是您的代码问题。稍等片刻,服务器应该会自行解决问题。

标签: javascript node.js discord discord.js


【解决方案1】:

错误不是你的。该错误可能是由 Discord 服务器或 discord.js 引起的。你可以等到它解决。也许几分钟。

【讨论】:

    【解决方案2】:

    我想向你展示我是如何在 discord.js v12 中制作我的禁令和临时禁令命令

    希望这段代码对你有什么帮助,感谢阅读

    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) 
        }
      }
    

    【讨论】:

      猜你喜欢
      • 2021-01-26
      • 2021-01-18
      • 1970-01-01
      • 2021-03-26
      • 1970-01-01
      • 2021-01-01
      • 2021-02-18
      • 1970-01-01
      • 2021-07-27
      相关资源
      最近更新 更多