Discord.js v12 昵称命令

时间:2021-01-19 15:51:32

标签: javascript discord discord.js

所以基本上我有这个 nick 命令,它改变了指定的用户昵称,但是如果我尝试在一个人身上运行该命令,例如“员工”角色,还有我,它会说它改变了我的名字,但我在控制台上出错。现在我假设它正在发生,因为我的机器人的员工角色处于更高的位置,我想知道命令是什么或如何修复它。

client.on('message', async message => {
  if(message.content.toLowerCase().startsWith(prefix + "nick")) {
    if(message.content.toLowerCase() == prefix + "nick") return message.channel.send('Pls mention someone and do `.nick @user [your text]`')
    const newEmbed = new Discord.MessageEmbed()
    .setColor("RANDOM")
    if(!message.member.hasPermission("MANAGE_NICKNAMES")) {
      return message.channel.send("You do not have permission to do that since you're missing `manage_nicknames` perm")}
      if(!message.guild.me.roles.highest.position) return message.channel.send("I can't change that user nickname since my role is lower than his one.")
      if(message.author.bot) return;
      if(message.guild === null) return
      let args = message.content.slice(prefix.length).split(/ +/);
      let mentionedUser = message.mentions.members.first() || message.guild.members.cache.get(args[1])
      if(mentionedUser.hasPermission("ADMINISTRATOR")) return message.channel.send("I can't change this user nickname since he has `administrator` perm")
      let name = args.slice(2).join(" ");
      newEmbed.setDescription("**Mention a user to change his nickname.**")
      .setTimestamp()
      newEmbed.setDescription(`I have successfully changed **${mentionedUser.user.tag}** nickname to **${name}**.`);

      mentionedUser.setNickname(name)
      message.channel.send(newEmbed);
  
} else {
  if(message.content.toLowerCase() === prefix + "help nick") {
    const newEmbed = new Discord.MessageEmbed()
    .setColor('#00B2B2')
    .setTitle('**Nick Help**')
    newEmbed.setDescription('this command is changing peoples names for example `.nick @user 123`.')
    .setFooter(`Requested by ${message.author.tag}`, message.author.displayAvatarURL())
    .setTimestamp();
    message.channel.send(newEmbed)
  }
}})

1 个答案:

答案 0 :(得分:0)

正如您所假设的,错误是由于机器人对这些员工的权限不足。

在您的问题中出现错误会很有用,但我猜是权限不足。

要解决这个问题,我所知道的唯一方法是将您的机器人在层次结构中的角色置于不和谐公会角色列表中的员工角色之上。