最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - discord.js v12 check if user is streaming - Stack Overflow

programmeradmin2浏览0评论

i'm using discord.js v12 and i wanted to have an PresenceUpdate method for when the user is streaming it says. I found this here but obviously it doesn't work. Is there any updated version to this?

    client.on('presenceUpdate', (oldMember, newMember) => {
    const channel = oldMember.guild.channels.find(x => x.name === "channel name");
    if (!channel) return;
        let oldStreamingStatus = oldMember.presence.game ? oldMember.presence.game.streaming : false;
        let newStreamingStatus = newMember.presence.game ? newMember.presence.game.streaming : false;

  if(oldStreamingStatus == newStreamingStatus){
    return;
  }

  if(newStreamingStatus){
    if (newMember.presence.game && newMember.presence.game.name === 'game name' || newMember.presence.game.details.match(/keywords in stream/gi)) {
        channel.send(`${newMember.user}, is live URL: ${newMember.presence.game.url}`);
    return; 
    }
  }
});

i'm using discord.js v12 and i wanted to have an PresenceUpdate method for when the user is streaming it says. I found this here but obviously it doesn't work. Is there any updated version to this?

    client.on('presenceUpdate', (oldMember, newMember) => {
    const channel = oldMember.guild.channels.find(x => x.name === "channel name");
    if (!channel) return;
        let oldStreamingStatus = oldMember.presence.game ? oldMember.presence.game.streaming : false;
        let newStreamingStatus = newMember.presence.game ? newMember.presence.game.streaming : false;

  if(oldStreamingStatus == newStreamingStatus){
    return;
  }

  if(newStreamingStatus){
    if (newMember.presence.game && newMember.presence.game.name === 'game name' || newMember.presence.game.details.match(/keywords in stream/gi)) {
        channel.send(`${newMember.user}, is live URL: ${newMember.presence.game.url}`);
    return; 
    }
  }
});
Share Improve this question asked Jul 14, 2020 at 1:52 PackOf20PackOf20 3342 silver badges20 bronze badges 2
  • 1 Please add the work you tried to do and the result of it (If there's an error add it too) in order to let someone help you more easily. – xTrimy Commented Jul 14, 2020 at 2:03
  • there is no error, that is literally it – PackOf20 Commented Jul 14, 2020 at 2:55
Add a ment  | 

2 Answers 2

Reset to default 4
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}.`);
        };
    });
});

https://discord.js/#/docs/main/stable/class/Presence

https://discord.js/#/docs/main/stable/class/Activity

https://discord.js/#/docs/main/stable/typedef/ActivityType

client.on("voiceStateUpdate", async(oldVoiceState, newVoiceState) => {
    if(newVoiceState.streaming){
        console.log("the user is streaming")
    }
});

This has worked for me. PresenceUpdate was not working for streaming.

发布评论

评论列表(0)

  1. 暂无评论