Make a list of kickable members in Discord.js(在 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!
推荐答案
你可以用 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 中列出可踢成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Discord.js 中列出可踢成员


- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- Fetch API 如何获取响应体? 2022-01-01
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07