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

Asked Jun 17, 2020·4 replies·Last activity 6 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

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 @member

the answer will be :

  • Nightbot : "This is a test @member"

But if i write :

  • ME : !test

the answer will be :

  • Nightbot : "This is a test @member" 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 !

4 replies

Hey @Trusty Penguin!

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);

Hey @Polar Cat !

Thanks you for your answer ! It's working perfectly ! But i have a second trouble.... 😅 !

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 😁 ! Thanks you for your help again :) !

slight_smile.pngsweat_smile.pnggrin.png

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.

That's really cool ! Thank you for your help @Polar Cat 😃 !

smiley.png