Can#39;t reach members(无法联系到成员)
问题描述
这是我在角色中显示成员的代码.但是当我为一个有很多成员的角色调用这个命令时,它只返回我的名字.我该如何解决?V12
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(`
・` + role.members.map(m => m.user.username + "#" + m.user.discriminator).join("
・"))
let m = await message.channel.send(inrole);
推荐答案
您好,您的问题是由于 Discord Api 最近网关更改导致 Guild
缓存为空,您需要启用这里的意图是为您解决问题 -
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 -
- 前往 Discord 开发者门户
- 选择您的应用程序
- 如果您向下滚动一点,在
bot
部分内,您将看到一个名为Privileged Gateway Intents
的部分 - 启用
SERVER MEMBERS INTENT
并重启bot,你会发现你的缓存不限于小数!
- 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 namedPrivileged Gateway Intents
- Enable the
SERVER MEMBERS INTENT
and restart the bot and you will find your cache is not limited to small number!
如果这仍然无效,请尝试获取所有公会成员 - message.guild.members.fetch()
在 Discord.js
If this still dosent work try fetching all guild members - message.guild.members.fetch()
Learn more about intents at Discord.js
这篇关于无法联系到成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法联系到成员


基础教程推荐
- Chart.js 在线性图表上拖动点 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 直接将值设置为滑块 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01