Get username in Twitchdevs Bot Tutorial

Hey,
I’m experimenting with the code given in “Getting Started with Chatbots & IRC” (twitchdevs)
and i want the bot to only execute an if statement when the command is invoked by a mod.
The problem is i don’t know how to refer to the user that typed since user is not defined in the given example.
So what exactly do you have to add in the function ‘onMessageHandler’ (line 25) to get the user who typed the message?

( https://gist.github.com/twitchdevelopers/afda75fe0a43453e97e97b25232778de#file-chatbot_getting_started-js )

Hey @RealKozie,

What you’re looking for is USERSTATE (https://dev.twitch.tv/docs/irc/tags#userstate-twitch-tags) which will return 1 for Mod and 0 if they’re not a Mod. As far as how to implement this following the tutorial I’m not in an environment to be able to test, but you’ll actually want to work beyond the message handler and in the commands context where target will be the user who executed the command.

So check if target has a value of 1 for Mod.

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