Trying to work out a custom command

I’m trying to write a command for a friend’s stream (in which I’m a mod) wherein the command checks the calling user’s userlevel & prints a different response depending on if they’re a mod/broadcaster or not. I could easily do this with two different commands, but I’d prefer to have it as one, so everyone can call the same command.

The idea is to let people have silly duels in chat. Here’s what I have currently, which works just fine, but only mods+ can use it. Normal users have no way to retaliate. I’m making a distinction between mods & not mods because mods have a sword to bonk with.

!editcom -ul=moderator !bonk $(user) swordbonks @$(touser)! Have at thee!

I’m getting lost in trying to figure out the JavaScript for the If/Else conditional inside the command (assuming I actually need to use one) to check the caller’s userlevel and print the different responses. In particular, I’m not sure how to pass the userlevel check into the JavaScript If/Else to be the conditional variable. What I would like to happen with the output is this:

Mod+ calls the !bonk command: [This is what happens with the current version of the command.]
@caller swordbonks @targetuser! Have at thee!”

Normal user calls the !bonk command:
@caller bonks @targetuser! Have at thee!”

To my understanding, I can’t call twitch commands/variables inside of the JavaScript segment. If I actually can, then this problem no longer exists, as I know how to write the command.

Any help or direction would be appreciated, especially if there’s an easier way to code what I’m trying to do. Thank you!

You can call nightbot variables inside of $(eval) I would recommend the $(userlevel) variable.
A list of nightbot variables and what they do is on here
You can use if/else to return the response I belive but it would be simplest to just do some like this:

$(eval "$(userlevel)"=="xxx"?"True":"False")

The eval will return True if the $(userlevel) is equal to xxx.
Any other value will return False.
(Essentially the exact same as if/else)

1 Like

Thank you, that is extremely helpful.

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