Greet if subscriber joined the channel

I am using tmi.js and i need it so that every time a subscriber joins channel i greet them

And what exactly are you having problems with?

You could poll the undocumented chatters endpoint tmi.twitch.tv/group/user/<ChannelName>/chatters to look for new users, when there are new users in the channel check if they are subscribed using the https://api.twitch.tv/kraken/channels/<channel ID>/subscriptions/<user ID> endpoint (https://dev.twitch.tv/docs/v5/reference/channels#check-channel-subscription-by-user) and then if they are send the greeting.

Personally though I wouldn’t recommend using a feature like this for many reasons, such as some users just like to lurk in a channel and not be announced when they join, the bot might spam a lot if a lot of subs join at once so you would need to limit/queue the greetings so your bot doesn’t exceed the limit and get a temp ban, and if you have subs rejoining frequently that will potentially be a lot of API requests unless you also implement caching on your end.

Thank you. I’ll try it and close this if it will work

Dist is correct. That is the best option… But as he also said, a lot of viewers don’t want announced when they join. I tried a similar system before and it was complained about constantly. While it is a fun idea possible make it toggleable per sub.

I got it to work, but now it returns giberish (probably gzip encoded) and i don’t know what to do!!!

Does the channel your testing this with have a subscription program (ie, an affiliate or partner)? When I tested requesting the subscriptions of a channel without a subscription program I noticed an encoded response (which really can just be ignored due to the status code).

Same thing happens if you do not have a proper OAuth either, doesn’t it? I swear when I messed up a copy/paste into curl before that I got back gibberish. I wonder if this person doesn’t a registered OAuth for the channel with proper permissions? Or isn’t passing the proper Authorization header, something like that perhaps?

EDIT: Yes, definitely, checking my own subscribers:

[morpheus] /opt/iobot2
illusion% curl -H ‘Accept: application/vnd.twitchtv.v5+json’ -H ‘Client-ID: asdf’ -H ‘Authorization: OAuth wrong_key’ -X GET https://api.twitch.tv/kraken/channels/77632323/subscriptions
Q??Y
?A
?@
Ы???t?x?^ vR’PH??(???>ޏ53?g?G>?5u?? ???r???U?Գ,]i?? ??X8Y??-?5?" ??5???R<=?f

[morpheus] /opt/iobot2
illusion% curl -H ‘Accept: application/vnd.twitchtv.v5+json’ -H ‘Client-ID: asdf’ -H ‘Authorization: OAuth right_key’ -X GET https://api.twitch.tv/kraken/channels/77632323/subscriptions
{"…ubscriptions":[{“created_at”:“2017-08-23T05:11:52Z”,"_id":"6338da7fc4a4d

@Rusty-b0lt do you have an OAuth with the channel_check_subscription scope for the channel as outlined in the Twitch docs you were referred to?

maybe i have an oauth without the flag that i need, i use this ihttps://twitchapps.com/tmi, it works, “which really can just be ignored due to the status code” - what is status code and how do i get it (the channel doesn’t have a subscribtion program)

I don’t use tmi.js for API stuff myself, but it it passes the response as well as the body back in the callback, then you can look at res.statusCode.which will give you the status code of the request.

If the OAuth doesn’t have the correct scope for the channel and endpoint you’re requesting you’ll get a 403 back, indicating The current authorization is not valid for this context. If it’s a 422 then for the subscription endpoint that’ll mean the channel doesn’t have a subscription program (and so you can’t check for the subscribers list or a specific users subscription because there is no subscription program to check).

If everything worked you would have gotten a 200 status code and then gone on to parse the body.

1 Like

Thank you i got an 422, this is closed

I suggest against using tmi.js's .api stuff. Use request directly in some form on Node. (I think this is a Node project anyways.)

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