Check if a username on the channel is a mod

Hi - I am not sure if this is the correct category for this question but here goes. In my JS code, I receive a chat message from my bot and it gives me a username. What I want to do is to check if that username is a mod on this channel and if so simply “return”. Is there someplace I can see a model of how this is done. Or the line that make that check. I think it has something to do with badges, but not certain. Thanks

Check the badges of the PRIVMSG to see if it contains a moderator badge

@badge-info=subscriber/92;badges=moderator/1,subscriber/90,ambassador/1;client-nonce=234f0b2816fb84fb201b7af6def7a2f5;color=#033700;display-name=BarryCarlyon;emotes=;flags=;id=9d5af3ef-ddcf-45f6-b526-0d72f959a1b9;mod=1;room-id=26610234;subscriber=1;tmi-sent-ts=1631718866602;turbo=0;user-id=15185913;user-type=mod :barrycarlyon! PRIVMSG #cohhcarnage :Mooo

If you parse the “badges” from that you can see I have the moderator badge.

How to extract this is up to you/depends how you are parsing chat.

With something like

Then under privmsg

Around line 255:

case 'PRIVMSG':
    if (payload.tags.badges.hasOwnProperty('moderator')) {
        // is moderator
1 Like

Thanks for this, it reinforces my thoughts on where to look. The thing that is now clear yet is how to get this PRIVMSG. All I am given by my bot is the username if want to interrogate and nothing else. How do I associate this username with a PRIVMSG?

Well you wrote the bot so you can change what it does.

Or you are using a library, and then the library may present this data.

The GitHub I linked to is a “library less” solution to read Twitch Chat.

Without seeing your code I’m not sure what answer to give you

Actually, my bot only extracts the username from a Stream Elements message. When my bot reads the SE message, if that username is a mod, I just want to exit the bot code. That’s the check I am doing. I may be on the wrong track, but it seems that I will have to do something like send a message to some interface with this username to get this PRIVMSG back.

Chainging stuff off other people/services bots is a problem.

Since if SE sent the message. Then you only have information about SE.

Sounds like you need

instead. And you can use the API to check if the user is a mod, but you’ll have to convert the username to a userID via the users API first

Which will add latency.

Or maintain a cache of the moderators in your bot to cross check names against

Ok. This gives me direction. I will use this advise to proceed from here. Thank you

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