問題描述
這是我在角色中顯示成員的代碼.但是當(dāng)我為一個(gè)有很多成員的角色調(diào)用這個(gè)命令時(shí),它只返回我的名字.我該如何解決?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 最近網(wǎng)關(guān)更改導(dǎo)致 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 開發(fā)者門戶
- 選擇您的應(yīng)用程序
- 如果您向下滾動(dòng)一點(diǎn),在
bot
部分內(nèi),您將看到一個(gè)名為Privileged Gateway Intents
的部分 - 啟用
SERVER MEMBERS INTENT
并重啟bot,你會(huì)發(fā)現(xiàn)你的緩存不限于小數(shù)!
- 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!
如果這仍然無效,請(qǐng)嘗試獲取所有公會(huì)成員 - 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
這篇關(guān)于無法聯(lián)系到成員的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!