问题
this is my code for displaying members in a role. But when i call this command for a role that has a lot of members in, it only returns my name. How i can fix it? V12
let role;
if(message.mentions.roles.first() || message.guild.roles.cache.get(args[0])) {
role = message.mentions.roles.first() || message.guild.roles.cache.get(args[0]);
if(!role)
return message.reply("I can't find this role!");
} else {
let choosenRole = args.slice(0).join(" ");
if(!choosenRole)
return message.reply("Please type a role name to check.");
role = message.guild.roles.cache.find(r => r.name === choosenRole);
if(!role)
return message.reply("I can't find this role!");
}
let inrole = new Discord.MessageEmbed()
.setColor("#09ba87")
.setAuthor(`${role.name}(${role.members.size})`)
.setDescription(`\n・` + role.members.map(m => m.user.username + "#" + m.user.discriminator).join("\n・"))
let m = await message.channel.send(inrole);
回答1:
Hey there your issue is because of recent gateway changes of the Discord Api that the Guild cache is empty , you need to enable the intents here is a fix for you -
- Head over to Discord Developers Portal
- Choose your application
- Inside the
botsection if you scroll a little bit down , you will see a section namedPrivileged Gateway Intents - Enable the
SERVER MEMBERS INTENTand restart the bot and you will find your cache is not limited to small number!
If this still dosent work try fetching all guild members - message.guild.members.fetch()
Learn more about intents at Discord.js
来源:https://stackoverflow.com/questions/65276256/cant-reach-members