Can't reach members

房东的猫 提交于 2021-01-20 13:51:14

问题


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 bot section if you scroll a little bit down , you will see a section named Privileged Gateway Intents
  • Enable the SERVER MEMBERS INTENT and 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!