user.ban不是功能吗?

时间:2020-05-14 15:02:19

标签: discord.js

我试图发出一个禁止命令,在此您可以出于某种原因禁止用户。

结果证明user.ban不是Discord.js V12中的功能,即使它应该是。

这是我的代码。

const { MessageEmbed } = require('discord.js');

module.exports = {
 name: 'ban',
 description: 'Bans a user.',
 category: 'Moderation',
 usage: '^ban <user> <reason>',
 run: async (bot, message, args) => {
  if (!message.member.hasPermission('BAN_MEMBERS')) {
   return message.channel.send('You do not have permission to do this! ❌');
  }

  if (!message.guild.me.hasPermission('BAN_MEMBERS')) {
   return message.channel.send('I do not have permission to do this! ❌');
  }

  const user = message.mentions.users.first();

  if (!user) {
   return message.channel.send('User was not specified. ❌');
  }

  if (user.id === message.author.id) {
   return message.channel.send('You cannot ban yourself! ❌');
  }

  let reason = message.content
   .split(' ')
   .slice(2)
   .join(' ');

  if (!reason) {
   reason = 'No reason provided.';
  }

  let Embed = new MessageEmbed()
   .setTitle(`Justice! | Ban Action`)
   .setDescription(`Banned \`${user}\` - Tag: \`${user.discriminator}\``)
   .setColor('ORANGE')
   .setThumbnail(user.avatarURL)
   .addField('Banned by', `\`${message.author.username}\``)
   .addField(`Reason?`, `\`${reason}\``)
   .setTimestamp();

  message.channel.send(Embed);

  user.ban(reason);
 },
};

有没有办法解决这个问题?

1 个答案:

答案 0 :(得分:0)

您获得的是用户而不是GuildMember。用户代表不和谐的人,而工会会员则代表服务器的成员。您可以使用mentions.members代替mentions.users来获得GuildMember而不是User:

    const user = message.mentions.members.first()