【发布时间】:2021-06-28 22:54:36
【问题描述】:
我知道您可以从用户中删除某些角色,并从用户中删除所有角色,但我正在考虑做相反的事情。我查看了这个guide,它提供了一种检索所有具有特定角色的人的方法。似乎您可以操纵集合/地图来遍历每个成员并删除角色。但是,我似乎无法做到这一点。
我已经硬编码了我要定位的一个特定角色以及应该触发该命令的消息。
我一直在尝试的当前代码(似乎只有在只有一个人分配该角色时才有效):
if (msg.startsWith('!new round')) {
//check for everyone and remove the role
//roleID is just the roleID number string; I've stated it outside the if loop, for other command use cases as well
let membersWithRole = message.guild.roles.cache.get(roleID).members;
console.log(membersWithRole);
for (let member of membersWithRole) {
let mem = member[1]
mem.roles.remove(role).catch(console.error);
message.reply("Everyone with the jail role is now back in the game!");
}
}
底线:给定具有指定角色的“公会”成员列表的集合(在指南中提供),我可以遍历列表* 以从每个成员中删除角色吗?
*我没有找到包含成员的列表,但它可能是对象本身,所以整个集合
【问题讨论】:
标签: node.js discord discord.js