Make a list of kickable members in Discord.js

爱⌒轻易说出口 提交于 2021-02-11 14:57:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!