【发布时间】:2021-04-11 14:52:01
【问题描述】:
所以我正在创建的不和谐机器人有一个抽搐通知,它使用 snekfetch 创建一个循环请求函数。在函数返回时,我有 client.channels.get(id).send(embed) 但它不会向我提供的频道 ID 发送消息。
const api = `https://api.twitch.tv/helix/streams?user_login=${streamer}`;
snekfetch.get(api).set('Client-ID', "XXXXXXXXXXXXXX").then(r => {
if (r.body.stream === null) {
setInterval(() => {
snekfetch.get(api).then(console.log(r.body))
}, 30000);
} else {
const embed = new discord.RichEmbed()
.setAuthor(
`${r.body.data.user_name} is live on Twitch`,
)
.setThumbnail(`http://static-cdn.jtvnw.net/ttv-boxart/live_user_${streamer}-500x500.jpg`)
.addField('Views', `${r.body.data.viewer_count}`, true)
return bot.channels.get(XXXXXXXXXXXX).send("TEST");
}
});
我已将我的客户端机器人命名为 bot.channels 而不是 client.channels
理论上它应该将 TEST 消息发送到我给它的任何频道 ID,但是我得到了一个错误。
(node:62565) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of undefined
at /Users/XXXXXXX/Desktop/HelperBot/main.js:61:50
at processTicksAndRejections (internal/process/task_queues.js:89:5)
(node:62565) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:62565) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
【问题讨论】:
-
确保您使用的是字符串作为 ID,而不是数字。 ID 是Snowflakes。
-
XXXXXXXX后面的value格式是什么?你能举个例子,但改变了 ID(将几个数字更改为不同的数字,但不要删除引号或任何其他字符)。如果您没有引号,那么懒惰的建议可能就是这种情况。
标签: javascript node.js discord discord.js