问题
So I am trying to clean up my old server, and I want my bot to kick everyone below a role named "bot". (and keep everyone above it) So I think (correct me if I am wrong) would be to create a list of kickable members and then kick each one (forEach). However, I can't find a way to make this list. Any help would be appreciated. Thanks!
回答1:
You can compare role positions with Role.comparePositionTo
// <guild> is a placeholder for the guild object
const role = <guild>.roles.cache.find(r => r.name === "bot") // get the role
<guild>.members.cache.each((member) => {
const highest = member.roles.highest; // get the member's highest role
// if the member's highest role is lower than the specified role, kick them
if (role.comparePositionTo(highest) > 0)
member.kick().catch(console.error);
});
来源:https://stackoverflow.com/questions/64487095/make-a-list-of-kickable-members-in-discord-js