Taging user after command

userstate is undefined and throwing an error because the tmi.js message event passes the arguments channel, userstate, message, and self, to your function. You’ve set userstate as the 5th argument of your function so the value will always be undefined.

You can look at the tmi.js docs to see what argumenta are provided by different events https://github.com/tmijs/docs/blob/gh-pages/_posts/v1.4.2/2019-03-03-Events.md#message so based on that you can see that argument you call context is what is the userstate object. You can either rename context to userstate, or where you reference userstate change that to context.

2 Likes