无法读取null的属性“ id”

时间:2019-11-04 17:24:39

标签: javascript null discord

我还没有设法使漫游器向用户添加角色。该机器人做出反应后就可以正常工作。

var roleName = reaction.emoji.name;
var role = reaction.message.guild.roles.find(role => role.name.toLowerCase() === roleName.toLowerCase());
var member = reaction.message.guild.members.find(member => member.id === user.id);

if (member.roles.has(role.id)) {
  member.removeRole(role.id).then(member => {
    console.log("Removed " + member.user.username + " from the " + role.name + " role.");
  }).catch(err => console.error);
}
else {
  member.addRole(role.id).then(member => {
    console.log("Added " + member.user.username + " to the " + role.name + " role.");
  }).catch(err => console.error);
}

0 个答案:

没有答案