[英]TypeError: Cannot read properties of undefined (reading 'path') in discord.js v13
[英]TypeError: Cannot read properties of undefined (reading 'fetch') Discord.js v13
嘗試從公會中的每個頻道獲取 10 條消息並讀取內容然后查看它們是否包含特定字符串但出現以下錯誤
TypeError: Cannot read properties of undefined (reading 'fetch')
這是我的代碼
interaction.guild.channels.cache.forEach(c => {
c.messages.fetch({limit: 10}).then(msgs => {
msgs.forEach(m => {
if (m.content.includes(interaction.options.getString('text',true))) {
// will do stuff here
}
}).catch(err => console.error(err))
})
})
interaction.guild.channels.cache
是GuildChannel的集合。
GuildChannels 結合了所有這些類別的頻道。
也許您需要在獲取消息之前檢查此條件。
interaction.guild.channels.cache.forEach(c => {
if(c.type == 'GUILD_TEXT'){
c.messages.fetch({limit: 10}).then(msgs => {
msgs.forEach(m => {
if (m.content.includes(interaction.options.getString('text',true))) {
// will do stuff here
}
}).catch(err => console.error(err))
})
}
})
您還可以過濾頻道
interaction.guild.channels.cache.filter((c) => c.type == 'GUILD_TEXT').forEach(c => {
c.messages.fetch({limit: 10}).then(msgs => {
msgs.forEach(m => {
if (m.content.includes(interaction.options.getString('text',true))) {
// will do stuff here
}
}).catch(err => console.error(err))
})
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.