Global variable

is it possible to make a global variable out of the message in a command? trying to make a link chain
i would put in !editlink www.soandso.com

and i would like to make it so that www.soandso.com became a global variable so that i can use it to edit these commands

!command edit !link “here i want the variable so that it becomes what i wrote in !editlink”
!command edit whats “here i want the variable so that it becomes what i wrote in !editlink”
!command edit join “here i want the variable so that it becomes what i wrote in !editlink”

@denniskarbon

Global variables are not possible to set up natively in Nightbot, but a workaround exists using ehsan’s quote API.


Click this link. It will generate three links and two tokens, a public token (8 characters long) and a private token (16 characters long). The public token is located within the first generated link. The private token is located within both the second and third generated links. The tokens are found after token= and before &data=$(querystring) Copy them down and keep them somewhere safe!

Below I have set up !editlink (mod-only) which stores the user input in the “global variable”. New input will overwrite the previously stored input. Replace PRIVATE_TOKEN with your private token.

!addcom -ul=mod !editlink $(eval a=`$(urlfetch https://twitch.center/customapi/addquote?token=PRIVATE_TOKEN&data=$(querystring))`;`The global variable is now set to "${decodeURIComponent(`$(querystring)`)}"`)

To set the global variable, type:

!editlink [input]

The following will then be the “global variable”. Replace PUBLIC_TOKEN with your public token:

$(urlfetch https://twitch.center/customapi/quote?token=PUBLIC_TOKEN&data=-1&no_id=1)

so all i would need now is

!addcom -ul=mod !editlink $(eval a=$(urlfetch https://twitch.center/customapi/addquote?token=PRIVATE_TOKEN&data=$(querystring));`

and then do !editlink www.soandso.com

then if i have other commands like !link all i would need is to copy paste in this to the message bar “$(urlfetch https://twitch.center/customapi/quote?token=PUBLIC_TOKEN&data=0&no_id=1)”

i have the right tokens just changed them for this.

when adding “$(urlfetch https://twitch.center/customapi/quote?token=5bee149c&data=0&no_id=1)” this to the message bar it doesnt seem to work

@denniskarbon Hide your tokens! If you share them, anyone can edit your lists.

And I would suggest:

!addcom -ul=mod !editlink $(eval a=`$(urlfetch https://twitch.center/customapi/addquote?token=PRIVATE_TOKEN&data=$(querystring))`;`The global variable is now set to "${decodeURIComponent(`$(querystring)`)}"`)

I highly recommend to add this command through the dashboard, so get rid of !addcom -ul=mod !editlink, so you don’t display your PRIVATE_TOKEN in chat.

And to use this as the variable:

$(urlfetch https://twitch.center/customapi/quote?token=PUBLIC_TOKEN&data=-1&no_id=1)

There’s a small change, it makes a big difference.

And I don’t know why it wouldn’t work, the link with your token works, so it should work. Did you put only the $(urlfetch)? If no, would you mind copy/pasting your message here, so we can have a look at it, but hide your tokens.

1 Like

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