列出Discord.js中可踢的成员的列表 [英] Make a list of kickable members in Discord.js

查看:24
本文介绍了列出Discord.js中可踢的成员的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在尝试清理旧服务器,并且希望我的机器人将所有人踢到名为"bot"的角色下面.(并让所有人保持领先)所以我认为(如果我错了,请纠正我)将是创建可踢成员的列表,然后对每个成员进行踢(forEach).但是,我找不到找到此列表的方法.任何帮助,将不胜感激.谢谢!

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!

推荐答案

您可以将角色位置与

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);
});

这篇关于列出Discord.js中可踢的成员的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆