javascript - 在 Discord.js 中列出可踢成员
问题描述
所以我正在尝试清理我的旧服务器,并且我希望我的机器人将所有人踢到名为“bot”的角色之下。(并让每个人都高于它)所以我认为(如果我错了,请纠正我)将创建一个可踢成员的列表,然后踢每个成员(forEach)。但是,我找不到制作此列表的方法。任何帮助,将不胜感激。谢谢!
解决方案
您可以将角色职位与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);
});
推荐阅读
- json - python:无法从线程中的文件加载json数据
- php - 向当前数组 PHP 添加一个键
- javascript - 是否可以将 instanceof 运算符结果作为值获取?
- progressive-web-apps - Ionic 4 + Stenciljs - 添加对谷歌分析的支持
- ruby-on-rails - Ruby on rails 不会在开发中重新加载
- excel - Excel公式搜索一个单元格并替换另一个单元格中的文本
- node-modules - 如何在 vue-cli 3 应用程序之间共享节点模块?
- python - 在 Python 中减去日期时间对象
- python - 使用 pandas 及时计算投资组合的价值
- .net - 在 http 请求中找不到 Saml2 响应