Pulling specific lines from a pastebin

Hello, I would like to make a command where if you type !currentgame (number from pastebin here), Nightbot pulls that line according to the typed number. For example: !currentgame 7 would pull: The current game is: Wonder Boy: The Dragon’s Trap;, according to the [pastebin (current game - Pastebin.com) I made. Also i would like only moderators to be able to use this command. There are a couple forums like this on this website, such as 1, and 2, but they dont have the information I need. Any help would be appreciated, thanks.

Hey @scrooooogemcduck!

I think there’s a better way to make your command if you’re on Twitch, thanks to the $(twitch) variable (you have nothing to edit in the code):

$(twitch $(channel) "The current game is: {{game}}")

If you still want to use your Pastebin, which I would strongly discourage on Twitch because there’s a better way to do it, but I know that if you’re on YouTube there’s no other way, then here’s the code:

$(eval g = `$(urlfetch json https://pastebin.com/raw/XXXXXXXX)`.split(`;`); i = parseInt('$(1)') - 1; g[i] ? g[i] : 'Error: wrong game ID';)

Replace XXXXXXXX with the Pastebin ID.

Also, if you’re using that method, you’ll need to fix you’re Pastebin: a semicolon is missing at the end of lines 20 and 39.

2 Likes

Thank you so much for your response! this saves me a lot of time, it really does. I tried it in chat and it works :slight_smile:

1 Like

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