# Check if a username on the channel is a mod

**URL:** <https://discuss.dev.twitch.com/t/check-if-a-username-on-the-channel-is-a-mod/33519>\
**Category:** Chat and IRC\
**Created:** [September 15, 2021, 3:13pm UTC](https://discuss.dev.twitch.com/t/check-if-a-username-on-the-channel-is-a-mod/33519 "2021-09-15T15:13:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![astro\_charles](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/astro_charles/32/12588_2.png) [@astro\_charles](https://discuss.dev.twitch.com/u/astro_charles)\
**Post date:** [September 15, 2021, 3:13pm UTC](https://discuss.dev.twitch.com/t/check-if-a-username-on-the-channel-is-a-mod/33519/1 "2021-09-15T15:13:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [September 15, 2021, 3:14pm UTC](https://discuss.dev.twitch.com/t/check-if-a-username-on-the-channel-is-a-mod/33519/2 "2021-09-15T15:14:47Z")

</div>

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!barrycarlyon@barrycarlyon.tmi.twitch.tv 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 [https://github.com/BarryCarlyon/twitch\_misc/blob/main/chat/chat.js](https://github.com/BarryCarlyon/twitch_misc/blob/main/chat/chat.js)

Then under privmsg

Around line 255:

```auto
case 'PRIVMSG':
    if (payload.tags.badges.hasOwnProperty('moderator')) {
        // is moderator
    }

```

---

<div class="post-metadata">

**Author:** ![astro\_charles](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/astro_charles/32/12588_2.png) [@astro\_charles](https://discuss.dev.twitch.com/u/astro_charles)\
**Post date:** [September 15, 2021, 3:31pm UTC](https://discuss.dev.twitch.com/t/check-if-a-username-on-the-channel-is-a-mod/33519/3 "2021-09-15T15:31:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [September 15, 2021, 3:32pm UTC](https://discuss.dev.twitch.com/t/check-if-a-username-on-the-channel-is-a-mod/33519/4 "2021-09-15T15:32:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![astro\_charles](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/astro_charles/32/12588_2.png) [@astro\_charles](https://discuss.dev.twitch.com/u/astro_charles)\
**Post date:** [September 15, 2021, 3:43pm UTC](https://discuss.dev.twitch.com/t/check-if-a-username-on-the-channel-is-a-mod/33519/5 "2021-09-15T15:43:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BarryCarlyon](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/barrycarlyon/32/253_2.png) [@BarryCarlyon](https://discuss.dev.twitch.com/u/BarryCarlyon)\
**Post date:** [September 15, 2021, 3:46pm UTC](https://discuss.dev.twitch.com/t/check-if-a-username-on-the-channel-is-a-mod/33519/6 "2021-09-15T15:46:35Z")

</div>

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

> **[Reference](https://dev.twitch.tv/docs/api/reference/)**
>
> Twitch Developer tools and services to integrate Twitch into your development or create interactive experience on twitch.tv.

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

> **[Reference](https://dev.twitch.tv/docs/api/reference/)**
>
> Twitch Developer tools and services to integrate Twitch into your development or create interactive experience on twitch.tv.

Which will add latency.

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

---

<div class="post-metadata">

**Author:** ![astro\_charles](https://d3ovvz0v2ajtpu.cloudfront.net/user_avatar/discuss.dev.twitch.com/astro_charles/32/12588_2.png) [@astro\_charles](https://discuss.dev.twitch.com/u/astro_charles)\
**Post date:** [September 15, 2021, 3:53pm UTC](https://discuss.dev.twitch.com/t/check-if-a-username-on-the-channel-is-a-mod/33519/7 "2021-09-15T15:53:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://d2opxh93rbxzdn.cloudfront.net/original/2X/0/05909729875cce3b53e59d5561c4d23bb14948fc.png) [@system](https://discuss.dev.twitch.com/u/system)\
**Post date:** [October 15, 2021, 3:53pm UTC](https://discuss.dev.twitch.com/t/check-if-a-username-on-the-channel-is-a-mod/33519/8 "2021-10-15T15:53:51Z")

</div>

Closed on October 15, 2021, 3:53pm UTC

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