这按预期工作,直到崩溃。每次用户开始直播时,它都会发布他们的直播链接。问题是,大约 5 分钟后,机器人崩溃了,我收到以下错误。
let oldStreamingStatus = oldMember.activities.find(activity => activity.type === 'STREAMING') ? true : false;
^
TypeError: Cannot read property 'activities' of undefined
我的代码如下。
client.on('presenceUpdate', (oldMember, newMember) => {
let oldStreamingStatus = oldMember.activities.find(activity => activity.type === 'STREAMING') ? true : false;
let newStreamingStatus = newMember.activities.find(activity => activity.type === 'STREAMING') ? true : false;
if (oldStreamingStatus == newStreamingStatus) {
return;
}
if (newStreamingStatus) {
if (newMember.member.roles.cache.some(r => ["Raider","Trial"].includes(r.name))) {
const activity = newMember.activities.find(activity => activity.type === 'STREAMING')
// console.log(newMember.activities)
client.channels.cache.get("731911793257087006").send(`Hey! ${activity.url} is streaming!`);
return;
} else
return;
}});
我尝试了下面的代码。但如果有人改变了他们的活动或者他们当前正在流媒体然后开始收听 Spotify,它会发布另一条消息。
client.on("presenceUpdate", (oldPresence, newPresence) => {
if (!newPresence.activities) return false;
newPresence.activities.forEach(activity => {
if (activity.type == "STREAMING") {
console.log(`${newPresence.user.tag} is streaming at ${activity.url}.`);
};
});
});
看来我需要 10 声望才能以正确的方式发布图片。我对此深表歉意。
catspeake
相关分类