【发布时间】:2021-10-19 20:17:37
【问题描述】:
我想在执行bot.on('ready', () => { }) 函数时获取特定频道的ID。我想这样做是为了在特定频道中重复发送一条消息。这是我现在的代码:
bot.on('ready', () => {
console.log(`${bot.user.tag} successfully logged in!`)
bot.user.setActivity('%help', ({type: "LISTENING"}))
function message() {
const channel = bot.channel.cache.find(ch => ch.id === 'id-of-channel');
if (!channel) return;
channel.send('message I am sending');
}
setInterval(message, 1000);
})
我得到的错误是:
Cannot read property 'cache' of undefined
任何帮助将不胜感激,谢谢!
【问题讨论】:
-
这可能属于 API 滥用,因为您会在短时间内发出如此多的请求。
-
另外,您遇到了什么错误?我怀疑是
Cannot read property 'cache' of undefined,如果你要买的话。 -
错误确实应该是
Cannot read property 'cache' of undefined,因为channel属性在Client类上不存在。属性是channels,你忘了s。 -
对这种混乱感到抱歉,(我对问题进行了更改),但是是的,我确实有这个错误@MrMythical 和 CypElf。
标签: javascript discord.js channel