Don't tag user if command $(touser) is empty

Hi all !

I try to find how i can use the $(touser) command with Nightbot and only tag the user @ (and don’t tag anyone when the ($touser) is empty !

For exemple whith the command " !test This is a test $(touser) " :

If i write :

  • ME : !test @User
    the answer will be :
  • Nightbot : “This is a test @User

But if i write :

  • ME : !test
    the answer will be :
  • Nightbot : “This is a test @ME” but i would like the answer was just “This is a test” and not tagging the user who called the command

If someone can help me or already know the answer, that will be niiiiice ^^ !
Thanks !

Hey @monsieurtu!

The solution is to test with $(query) because it can be empty:

$(eval `$(query)`?`This is a test $(touser).`:`This is a test.`;)

Or with if{}else{}:

$(eval if(`$(query)`){`This is a test $(touser).`}else{`This is a test.`})

Another solution could be to test if $(user)==$(touser) too:

$(eval `$(user)`==`$(touser)`?`This is a test.`:`This is a test $(touser).`;)

Note: ?: is a ternary operator, it works like this (test/condition)?(if true):(if false);

1 Like

Hey @Emily !

Thanks you for your answer ! It’s working perfectly ! But i have a second trouble… :sweat_smile: !

Now it write the first word afer the command, but I would like to take it only if it’s an @ ! ^^

For exemple :
If I write : “!test testing”
Nightbot will answer : “This is a test testing”

But if it’s not an @ i would like nightbot write : “This is a test”

It’s a brainwash for me :grin: ! Thanks you for your help again :slight_smile: !

Oh okay, so you wanted the @ included, so here’s a fix:

$(eval `$(query)`.includes(`@`)?`This is a test $(touser).`:`This is a test.`;)
$(eval if(`$(query)`.includes(`@`)){`This is a test $(touser).`}else{`This is a test.`})

Note: the @ isn’t actually necessary on Twitch, so some people might not use it to tag people, this could be an issue as this wouldn’t work for them.

1 Like

That’s really cool ! Thank you for your help @Emily :smiley: !

1 Like

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