How to recognize new subscribers and then change their status

I am pretty new to Twitch so I need basic help. I am modifying the JavaScript created via a “Custom Widget”. What I am trying to do is to gift certain users as they subscribe to my channel by making him/her a VIP (I assume trough the “isVIP” boolean). I am using Java Script created a Stream Elements (SE)custom widget but although I can get a notification when a user subscribes, SE does not give me access a user’s properties, so now I am at square one.

Based on what I described above, can anyone point me to a JS boilerplate where something similar may have been done. If not, what steps would I need to set this up and then gain access to a users to make him/her a VIP.

Thank you for any guidance I can get.

VIP requires a token from the broadcaster, since only the broadcaster can VIP/UnVIP users

So I doubt you’d find a boilerplate for that.

Your best bet here is to skip Stream Elements all together and build a chat bot.

That will listen for a new subscriber and then VIP the subscriber. But it will need to be logged in as the broadcaster.

You’d probably run out of VIP’s quick, since you only have a finite number of VIP Slots.

Thank you so much. This information greatly helps. I have played around with a simple bot previously, so that should get me started. A couple of quick questions about your comments

That will listen for a new subscriber and then VIP the subscriber. But it will need to be logged in as the broadcaster.

When you says “listen”, do you mean the “client.on” command. Will I just need to use something like: “client.on(‘sub’, (channel, tags, message, self) …” ? or is there some other method to listen for a new subsriber?

> You’d probably run out of VIP’s quick, since you only have a finite number of VIP Slots.

Thanks for this tip. I was not aware of this. The gifted VIP is only for 24 hours, so I plan to store the user’s info in a db and then each day run through it to clear out those who have expired. Do you see a problem with this approach?

Sorry for these basic questions but I am just getting started on this platform.

Thanks again.

client.on sounds like you are using a library, so refer to that libraries documentation. I personally don’t use a library for my bots (beyond WS for connection handling) so to “listen” for a sub I parse the relevant message(s) in chat.

By “listen” I mean “listen/read in chat like how you would as a human reading chat”

So I “listen” for USERNOTICE messages for Subscriber events

Sounds similar to what I do elsewhere so that looks fine.

Thank you again. I think I have enough info now to start on the right track.

Regards

Sorry for all the questions but I have built the bot but you say I have to be logged in as the Broadcaster to change VIP status. Do you mean such as:

const client = new tmi.Client({
options: { debug: true },
identity: {
username: <broadcaster’s Twitch Username>,
password: <broadcaster’s Twitch Password>
},
channels: [ process.env.CHANNEL_NAME ]
});

Is this what you mean?

And when I change the VIP status I would GET a user’s record and change the VIP bit - or is there an easier way?

Thanks

There is no API to GET that returns VIP status.

So your bot can call /vips to list current VIP’s
Or store them in a DB as your VIP/unvip them

To set/unset VIP you run the chat command for .vip username or .unvip username

You don’t use account passwords to connect to chat. You need the broadcaster to go though your apps OAuth flow Getting Tokens: OAuth | Twitch Developers and requesting the appropriate scopes to connect to chat and any others that your bot may need.

Thanks to your direction, I am making progress on this. I have successfully set up the Twitch API Authentication index.js using Node, Express, Passport and the requested Scopes. Based on the output from that, it seems it is correctly set up as it is returning the ACCESS and REFRESH tokens. I also have have an app.js file which is also monitoring Port 3000.

Because this is my first time doing this, I am stuck on where to go next. In particular, where should my js code go that will monitor chat and do what I need it to do. In app.js? In index.JS? neither? I don’t know how to connect all this together and start the bot so it does the appropriate interaction with chat. An pointer to an example app would be helpful if it exists.

Thank you for helping guide this “first timer” through this process

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.