即使命令运行正常,我也遇到了错误 (节点:1907)UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“ fetchMembers”
client.on('message', async message => {
let guild = await message.guild.cache.fetchMembers();
let roleID= '644235497169748037';
let roleID1= '615852982734684181';
let roleID2= '615852983330013212';
let roleID3= '615852992230588427';
let roleID4= '722513324151144552';
let memberCount = guild.roles.get(roleID).members.size;
let memberCount1 = guild.roles.get(roleID1).members.size;
let memberCount2 = guild.roles.get(roleID2).members.size;
let memberCount3 = guild.roles.get(roleID3).members.size;
let memberCount4 = guild.roles.get(roleID4).members.size;
let memberCountChannel = guild.channels.get("733035179756486737")
let memberCountChannel1 = guild.channels.get("732530240420839464")
let memberCountChannel2 = guild.channels.get("732530312713863178")
let memberCountChannel3 = guild.channels.get("732530713898909746")
let memberCountChannel4 = guild.channels.get("732530791686602833")
memberCountChannel.setName("Guild Members: " + memberCount)
memberCountChannel1.setName("Wizard: " + memberCount1)
memberCountChannel2.setName("Witch: " + memberCount2)
memberCountChannel3.setName("Shai: " + memberCount3)
memberCountChannel4.setName("Compass: " + memberCount4)
});
答案 0 :(得分:0)
Discord JS v12引入了管理器的概念,您将不再能够在诸如Collection#get
之类的数据结构上直接使用诸如Client#users
之类的收集方法。现在,您在尝试使用收集方法之前必须直接在管理器上请求缓存。
您需要更改:
guild.roles.get(roleID)
// to
guild.roles.cache.get(roleID)
和:
guild.channels.get(channelID)
// to
guilds.channels.cache.get(channelID)
我在您的代码中看到的另一个错误是您试图访问Guild的属性cache
,该属性不存在(message.guild.cache.fetchMembers()
)。
您必须使用:
message.guild.members.fetch()