Pass Nightbot variable through !editcom

Hello NightDev Community,

I have a question about the Custom Commands, because I’m a bit lost after reading the docs. I am trying to implement a command for the streamer on Twitch, whose mod I am, which allows users to get a lobby code (in this case Phasmophobia), but since this changes every time a lobby is created, I would now be interested in whether you can also pass a variable. Something like:

!phasmo [code] → sets Phasmocode - only Mods
!phasmo → outputs the code - all3

As far as I know, you can only pass static values like this:

!addcom !phasmo The current lobby code to play with is: EU-

and would have to change it every time. Is this so far correct, or is there another possibility that I have not yet come across.

If it was a static and fixed value, it would be a lot easier I think.

Excuse my English spelling, but I am not a native speaker and since I can not be 100% sure of every word and phrase, I used a translator.

Thanks a lot for your answers and help!

Kind regards

Denny143

Alright.

Since i’ve found another post on the forums regarding “keeping strings” i know use this solution.

!addcom !phasmo_code -ul=mod -a=!editcom !phasmo $(query $(touser) "Der Code lautet: EU-{{query}}")

!addcom !phasmo Command isn't set yet

Problem is, i can’t get it to send the complete string. Just the number.

Maybe you got some ideas, for refference take look at the gif.
msedge_4UQYyUeUhh

1 Like

Hey @denny143!

You’re close, but it seems like you mistook $(query) for $(twitch); you actually use $(query) like you’d use $(touser), that means $(query) represents a string: what you enter after the command name.


Also, another subtlety you can’t be aware of because we’ve not shown much how to do it on the forum, if you want to edit a command’s content, but keep/pass a Nightbot variable in/to the edited command, you need to cut it in parts so the bot doesn’t replace it with the content you just entered.
For example, the following command:

!settest -a=!editcom !test $(touser) | TEST | $(query)

would edit !test’s message as such:

!settest hello world →  The command "!test" has been edited successfully.
!test → hello | TEST | hello world

when what you actually wanted was:

!test → $(touser) | TEST | hello world

The solution to that is to use JavaScript through the $(eval) variable to cut and combine the variable:

$(eval '$' + '(touser)') → $(touser)

Editing the original command of my example, you’d get:

!settest -a=!editcom !test $(eval '$' + '(touser)') | TEST | $(query)

So here’s how to write your !phasmo_code command:

!editcom !phasmo_code -ul=mod -a=!editcom !phasmo $(eval '$' + '(touser)' + ' Der Code lautet: EU-$(query)')

I appreciate that you put the effort to write in English, and that you gave it a try on your own, thank you!

1 Like

Thank you, this really helped. :smiley:
I didn’t know how to handle it, and i was looking for a solution similar to code (phyton for example) where it would be

A = input('')
B = A
A
print(B)

Something like that.

1 Like

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