NightDev Community Forums

Multiple Arguments

Heyo. I’m trying to figure out how to create a command so when someone types something like:

“!detect magic @FakeUsername

The result would be:

@FakeUsername is X% magic.”

I know how to do the percentage roll. I’m just trying to figure out how to get it so the first argument and second argument can be placed in specific spots in the message. So basically, “magic” could be anything that the person types in, like “awesome” or “cool”.

Also, if someone doesn’t add a user in the second argument then it would default to the user that typed the message. So essentially defaulting to $(user) if there is no second argument.

Much appreciated.

Hey @pipedreamdx!

The solution is the following:

!addcom !detect $(eval q=decodeURIComponent(`$(querystring)`).split(` `);q.length==1?u=`$(user)`:u=q.pop();`${u} is ${Math.floor(Math.random()*101)}% ${q.join(` `)}`)

Basically I look at how many words were sent, if there was only 1 I default to $(user), if there was more than one, I assume the last one is the target and I go with it.
It means that you can add more than 1 word as first argument, but if you do, you need to specify the target at the end, otherwise it won’t work as expected.