【发布时间】:2021-01-03 22:40:55
【问题描述】:
我正在使用 discord.js 版本 12.3.1 并尝试创建一个系统,用户可以在其中对消息做出反应并从中接收角色。当您单击??????时,您将获得“蓝色”角色。如果您然后单击????,例如,您的????反应被移除,您将获得“绿色”角色。
问题在于添加新角色并不能始终如一地工作。即使确认添加的角色不在已删除角色的集合中,添加的角色有时也会添加给用户,然后立即删除。
我认为导致问题的具体行:
const addRole = guildRoles.find(role => role.name === colorRoles[emojiName])
// addRole: Role (ex. with name 'GREEN')
guildMember.roles.add(addRole)
const removeRoles = guildRoles.filter(role => Object.values(colorRoles).filter(color => color !== colorRoles[emojiName]).includes(role.name))
// removeRoles: Collection of Roles (ex. with names 'BLUE', 'RED', 'YELLOW')
guildMember.roles.remove(removeRoles)
// At this point 'GREEN' is added and removed; all other color roles are removed
Full method with more context on Pastebin
我不明白为什么新添加的颜色角色有时会立即被删除,非常感谢一些建议。
【问题讨论】:
标签: javascript discord discord.js