【发布时间】:2019-07-24 01:16:21
【问题描述】:
我正在尝试让我的不和谐机器人每隔几个小时向我发送一条消息,所以我知道它仍在运行。
例如:
机器人向我发送“仍在运行!”每两个小时给我一次。
这是我尝试过的一些代码,但它不起作用:
client.on("ready", () => {
client.user.setActivity("a game.");
if (timeout) {
clearInterval(timeout);
}
timeout = setInterval(() => client.channels.get("<ID Retracted>").send("Still functioning!"), 7200000);
console.log("READY");
});
这是我得到的错误:
Jump to /app/index.js:26
timeout = setInterval(() => client.channels.get("<retracted id>").send("Still functioning!"), 7200000);
^
TypeError: Cannot read property 'send' of undefined
at Timeout.setInterval [as _onTimeout] (/app/index.js:26:74)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)
【问题讨论】:
-
您随后得到了什么结果和/或错误?
-
@rhand 错误现在在 OP 中。
-
看起来
client.channels.get("<retracted id>")没有找到频道:如果您尝试在命令中执行它,它会获得频道吗?
标签: node.js discord discord.js