Hey @MichiTriste!
Funnily enough, the very first question I asked on this forum was pretty similar, here’s the answer I got:
Basically, you want to add a test on the Nightbot variable you use in your code, but how you implement the test depends on what variable you use:
$(query)
and$(querystring)
give an empty string when no argument are fed into the command
→ so you test it that way:if ('$(query)' === '')
- arguments like
$(1)
or$(8)
give anull
when no argument are fed into the command
→ so you test it that way:if ('$(1)' === 'null')
- finally
$(touser)
always responds with something: when no argument are fed into the command it gives$(user)
→ so to test if the user of the command@
'd someone:if ('$(touser)' != '$(user)')
Since $(touser)
is equivalent to $(1)
, but doesn’t require the use of $(user)
in the test, I’ll use the latter for the example:
$(eval if ('$(1)' === 'null') { 'MESSAGE_IF_NO_INPUT' } else { 'MESSAGE_IF_INPUT' })
or with ternary operators:
$(eval '$(1)' === 'null' ? 'MESSAGE_IF_NO_INPUT' : 'MESSAGE_IF_INPUT')