Discord.js版本12我无法禁止用户

时间:2020-04-09 11:10:37

标签: javascript discord discord.js

我正在使用discord.js版本“ 12.1.1”,对于此脚本“ banuser.js”,我正在使用命令处理程序。

现在我只想禁止该人,但我不断收到此错误: (节点:30800)UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“ banable”

如果可以的话,很酷的功能是 取消禁令+定时禁令->当我禁止某人时,我可以说1/7天或以小时为单位... 但是现在我想使其发挥作用,以便禁止他人。

const discord = require("discord.js");

module.exports.run = async (bot, message, args) => {

  if (message.member.hasPermission("BAN_MEMBERS")) {

      if (!message.mentions.users) return message.reply('You must tag 1 user.');

      else {

          const channel = message.guild.channels.cache.get("696692048543088691");
          const member = message.mentions.members.first();
          let reason = message.content.split(" ").slice(2).join(' ');

          if (member.banable== false) return message.channel.send("That user cannot be baned!");

          else {

              if (!reason) reason = (`No reason provided.`);

              await member.send(`You have been baned from **${message.guild.name}** with the reason: **${reason}**`)
                  .catch(err => message.channel.send(`⚠ Unable to contact **${member}**.`));

              await member.ban(reason);

              const banEmbed = new discord.MessageEmbed()
                  // .setAuthor(member.user.tag, member.user.iconURL()) -> kleine avatar
                  .setAuthor(member.user.avatarURL())
                  .setThumbnail(member.user.avatarURL())
                  .setAuthor(member.user.tag)
                  .setColor("#ee0000")
                  .setTimestamp()
                  .addField("Kicked By", message.author.tag)
                  .addField("Reason", reason);
                  // console.log(member.user.avatarURL('Heeft geen avatar'))

              await channel.send(banEmbed);

              console.log(`${message.author.tag} Baned ${member.user.tag} from '${message.guild.name}' with the reason: '${reason}'.`);

          }
      }
  } else {
      message.channel.send("You do not have permission to use the ban command.");
      return;
  }
}


module.exports.help = {
  name: "banuser"
}

/* module.exports.run = async (bot, message, args) => {

    if (!message.member.hasPermission("BAN_MEMBERS") || !message.member.hasPermission("ADMINISTRATOR")) return message.channel.send("You don't have a permissions to do this.");
    let user = message.mentions.users.first();

    let member = message.guild.member(user);
    let reason = args.slice(22).join(" ");

    if (!user) return message.channel.send("Please mention the user.");
    if (user.id === message.author.id) return message.channel.send("You can't ban yourself.");
    if (user.id === client.user.id) return message.channel.send("You can't ban me.");

    if (!reason) reason = "No reason provided";

    member.ban(reason).then(() => {
      message.channel.send(`Successfully banned **${user.tag}**`);
    }).catch(err => {
      message.reply("I was unable to ban the member.");
    })
}
module.exports.help = {
    name: "banuser"
} */

到目前为止,这是我的代码

1 个答案:

答案 0 :(得分:1)

您必须将if (!message.mentions.users) return message.reply('You must tag 1 user.');替换为if (!message.mentions.members) return message.reply('You must tag 1 user.');

保持const member = message.mentions.members.first();不变

然后将member.banable替换为member.bannable