繁体   English   中英

我不断收到类型错误:无法读取未定义的属性“缓存”

[英]I keep getting the TypeError: Cannot read property 'cache' of undefined

我在 discord.js 中创建了这个不和谐的欢迎器,但我不断收到此错误:

const message = welcome <@${member.id}> to music and chill! please read the ${member.guild.channel.cache.get(ruleschannel).toString()} welcome <@${member.id}> to music and chill! please read the ${member.guild.channel.cache.get(ruleschannel).toString()} ; ^

类型错误:无法读取未定义的属性“缓存”

这是我的代码:

module.exports = (client) => {
   const channelid = "865471665168580628";
   client.on("guildMemberAdd", (member) => {
       const serverid = member.guild.id
       const guild = client.guilds.cache.get(serverid.toString());

       console.log("member");
       const ruleschannel = guild.channels.cache.find(channel => channel.name === "rules");

       const message = `welcome <@${member.id}> to music and chill! please read the ${member.guild.channel.cache.get(ruleschannel).toString()}`;

       const channel = member.guild.channels.cache.get(channelid);
       channel.send(message);
   })
}

我阅读了很多问题和大量答案,但没有任何帮助,有人可以帮助我吗?

很可能是打字错误

试试${member.guild.channels.cache.get(ruleschannel).toString()} 频道后缺少s${member.guild.channel.cache.get(ruleschannel).toString()}

guild没有名为channel属性,而是channels 所以它说undefined并且不能调用undefined cache

https://discord.js.org/#/docs/main/stable/class/Guild

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM