Command where Nightbot prints the query but defaults to the user if no query is given

I’m trying to make a command that prints the entire query given or, if no query is given, the command user’s username.

Examples:

!example test → Nightbot: Test is nice!
!example → Nightbot: Dimentive is nice!

I’ve tried a few different things but to no avail. It’s going to be an 8-ball-esque command which gives you a random word, so I don’t know how to make this work.

Any help is greatly appreciated!

@Dimentive

$(eval decodeURIComponent(`$(querystring)`)||`$(user)`)
1 Like

That’s exactly what I was looking for! Thank you so much! Works perfectly.

You’re incredible.

I want to have a command where instead of printing the command user’s username if no query is given, it prints a string of regular text, but I couldn’t get it to work; it just prints nothing but a space if no query is given.

Do you know how I could make this work?

This should work:

$(eval decodeURIComponent(`$(querystring)`)||`output if there is no query`)

It prints out the input, but if there’s no input it’ll output whatever text comes after ||

1 Like

That works perfectly; however, I tried having text before the $(querystring), but that causes it to not work. Do you know how I’d get around this?

Not sure I follow what you’re saying. Could you paste your command response as is, some screenshots of you testing the command, and what the desired vs actual output of each test case is?

Here’s the command syntax:

!addcom -cd=5 !hug $(user) $(eval decodeURIComponent(`hugged $(querystring)`)||`hugged… themselves. Awkward`)! $(count) hugs have been given.

This command works with a query, but if no query is given, it doesn’t work.

With query (!hug test), the output is: Dimentive hugged test! 5 hugs have been given.
Without query (!hug), the output is: Dimentive hugged ! 3 hugs have been given.

Putting “hugged” inside $(eval) like that breaks the logic. Put it outside instead.

!addcom -cd=5 !hug $(user) hugged $(eval decodeURIComponent(`$(querystring)`)||`themselves. Awkward`)! $(count) hugs have been given.
1 Like

I know, but I wanted the “hugged” to have an ellipsis if no query is given. Although I can live without it if there’s no way around it.

Thanks for all the help, though. You’re the MVP.

Hiya, small edit to add the ellipsis:

!addcom -cd=5 !hug $(user) hugged$(eval a=decodeURIComponent(`$(querystring)`); a?` `+a:`... themselves. Awkward`)! $(count) hugs have been given
2 Likes

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