【发布时间】:2020-11-06 17:37:35
【问题描述】:
我尝试用于向特定频道发送消息的每一行代码在 discord.js v12 中似乎都不起作用,即使我从官方文档中获得了该代码。这是我的代码:
const Discord = require('discord.js');
const client = new Discord.Client();
const announcementChannel = client.channels.cache.get(process.env.CHANNELANN);
let announcement = "MESSAGE HERE";
client.on("presenceUpdate", (oldPresence, newPresence) => {
if (!newPresence.activities) return false;
newPresence.activities.forEach(activity => {
if (activity.type == "STREAMING") {
if(newPresence.user.id == "THE ID IS HERE") {
announcementChannel.send(announcement);
}
} else {
client.user.setActivity("over the server", {
type: "WATCHING"
});
};
});
});
client.login(process.env.TOKEN);
这是我收到的错误:
announcementChannel.send(announcement);
^
TypeError: Cannot read property 'send' of undefined
【问题讨论】:
-
process.env.CHANNELANN 是 ID、名称还是其他?
-
没关系,我现在可以使用
client.channels.cache.get(process.env.CHANNELANN).send(announcement);修复它但是,现在它只会不断发送垃圾邮件,并且不会只发送一次然后停止。你知道有什么解决办法吗?
标签: javascript discord discord.js