首页 > 解决方案 > “无法读取未定义的属性‘缓存’”?

问题描述

我正在使用 Discord.js V12

我正在尝试按 ID 向特定频道发送消息

我得到了频道 ID,并使用下面的代码将其存储在ChRules中

const ChRules = client.channels.cache.find(c => c.name === '│rules-and-info').id

因此,当我尝试按 ID 向频道发送消息时,我使用下面的代码

client.channels.cache.get(ChRules).send("Follow the rules");

但由于某种原因,我得到了错误

TypeError:无法读取未定义的属性“缓存”

我的机器人在一个服务器上,所以我不明白为什么会出现这个错误

client定义为const client = new Discord.Client();

标签: javascriptnode.jsdiscorddiscord.js

解决方案


这应该工作

const ChRules = client.guild.channels.cache.find(c => c.name === '│rules-and-info')
ChRules.send("SEND");

推荐阅读