如何查看用户是否将角色存储在变量中?

时间:2019-04-16 03:49:56

标签: javascript node.js bots discord discord.js

我正在为我的机器人执行角色分配命令,因此用户可以键入h.addrole @user @role,如果该用户具有该角色,我将尝试输入该字符,每次我尝试输入时,都会输出This user already has this role!使用命令,它总是输出
(node:5224) UnhandledPromiseRejectionWarning: TypeError: userToModify.hasRole is not a function
我的代码如下:

} if (message.content.startsWith(config.prefix + "addrole")) {
  let userToModify = message.mentions.members.first();
  let roleToAdd = message.mentions.roles.first();
  if (userToModify.hasRole(roleToAdd)) return message.channel.send("This user already has this role!")
  if (!args) return message.channel.send("Please enter a mentioned user and a mentioned role to assign (e.g h.addrole @Brickman @Moderator")
  if (!message.member.hasPermission("MANAGE_ROLES")) return message.channel.send("You do not have permission for this!")
  userToModify.addRole(roleToAdd); 
  return message.channel.send("Succesfully added role " + roleToAdd + " to member " + userToModify + "!");

1 个答案:

答案 0 :(得分:1)

就像说... $sql = "SELECT * FROM oath WHERE name LIKE '%".$query."%' AND phone LIKE '%".$mob."%'"; 不是函数。

相反,请尝试如下操作: hasRole