[英]Get all users with specific role using discord.js
I'm getting RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number: undefined.
我收到RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number: undefined.
with this code.使用此代码。 Can someone help me with what's undefined
here?有人可以帮我解决这里undefined
的问题吗?
I'm using discord.js v13.6.0.我正在使用 discord.js v13.6.0。
require('dotenv').config();
const token = process.env.bot_token;
const { Client, Intents } = require("discord.js")
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.NON_PRIVILEGED,
Intents.GUILD_MEMBERS
]
});
const prefix = '!getUserByRole';
client.on("messageCreate", (message) =>{
if(!message.content.startsWith(prefix) || message.author.bot || message.author.id) return;
const args = message.content.slice(prefix.length).split(/ +/);
const roleId = args[1];
message.guild.members.fetch().then((members)=>{
members.filter(mmbr => mmbr.roles.cache.get(roleId)).map(m => {
console.log(m.user.tag, m.user.id);
});
})
})
client.login(token);
In discord.js v13 Intents.ALL
, Intents.NON_PRIVILEGED
, and Intents.PRIVILEGED
have all been removed to discourage bad practices.在 discord.js v13 Intents.ALL
中, Intents.NON_PRIVILEGED
和Intents.PRIVILEGED
都被删除以阻止不良做法。 It means you need to remove Intents.NON_PRIVILEGED
.这意味着您需要删除Intents.NON_PRIVILEGED
。
Also, there is no Intents.GUILD_MEMBERS
, it should be Intents.FLAGS.GUILD_MEMBERS
.此外,没有Intents.GUILD_MEMBERS
,它应该是Intents.FLAGS.GUILD_MEMBERS
。 So you'll need to update your code like this:所以你需要像这样更新你的代码:
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MEMBERS,
],
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.