簡體   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