tmijs / tmi.js

💬 Javascript library for the Twitch Messaging Interface. (Twitch.tv)
https://tmijs.com
MIT License
1.54k stars 217 forks source link

How to know if a user is a subscriber/follower #421

Closed whitepapercg closed 3 years ago

whitepapercg commented 3 years ago

Hello! I am a newcomer, so please do not swear too much. My searches are at a dead end. I need to check if the user is a follower to the channel. Is there a ready-made solution for this? Can you help me?

AlcaDesign commented 3 years ago

Why would we swear?

You title says "subscriber" but the post says "follower" so I'll give you both:

To determine if a user is a subscriber in a chat message, check the badges object in the tags for "subscriber":

client.on('message', (channel, tags, message, self) => {
    if(self) return;
    const { badges = {} } = tags;
    if(badges.subscriber) console.log(tags.username, 'is a sub');
});

tmi.js has no way to determine a follower, you need to use either the Helix (new) or Kraken (old) API. This is unrelated to tmi.js and that official documentation has plenty of information.