Parsing variables from pastebin, but only sometimes?

Asked Aug 30, 2025·7 replies·Last activity 11 months ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

Hello! I'm working on a command that posts a random line of text from a video game. In that game, you can name your own character, so I thought it would be fun if I could use the dialogue including the player's name, and replace that with the user who called the command. I did some searching, and this thread: /t/nightbot-command-with-pastebin-tagging-a-user/1534640086879178874#m1534640… was the closest to what I'm trying to do.

I adapted it to my situation (I'm only working with one variable, and that thread has two), and did some testing on a simple paste with only lines which contain the $(user) variable, represented as "${u}", and it worked! However, when I try the command on my entire document, I get a "[Response must be less than 400 characters]" error.

I was kind of agonizing over this for a while, trying different stuff. But I think the issue is that the command is expecting to find a user variable in every result? If my document has one on every line, it works; if not, it doesn't.

This is what my code is looking like right now (I'm using github gists instead of pastebin because pastebin called my text "explicit" or something):

$(eval u=`$(user)`; p=`$(urlfetch https://gist.githubusercontent.com/webcamcals/78ee5273639b0cc5e72c4559b0d8f64d/raw/006d6e9d70f75e697bd31fefe5e12956714155a6/crystal)`.split(`#`); p[Math.floor(Math.random()*p.length)])

If I'm right about what's causing the issue (I could easily be wrong, I'm not a programmer 😛), is there a way to fix this so that it will parse variables when relevant, but not break if there isn't one on every line? Thanks!

7 replies

Hmm, I was doing some more searching, and maybe the expectation for a variable isn't the problem?

/t/response-must-be-less-than-400-characters-issue/1534610779439890653#m15346…

In this thread, the problem was caused by characters used to define variables appearing in the json. And my json is pretty big; I did my best to get rid of characters like quotation marks that usually cause problems. But I'll scrutinize it a bit more and see if I notice anything there. Since the error in my case is the same error this user was getting (over character limit), maybe I have the same problem.

Edit: My search isn't turning anything up. I have ' characters in my text, but that can't be it. I've tried removing ":"s, and that didn't help either.

I have no experience using Github but I do have Pastebin, so in the latter it is necessary to use quotes and a comma (,) at the end of each line so that when using urlfetch each line appears separately and not everything as a single response.

For example

["answer1",
"answer2",
"answer3]

What you quoted in says that if you use a type of quotes in the command syntax within Nightbot, check that you are not using the same ones within Pastebin.

So if you replace your Github answers with the format that I share with you, I think it would be working

Out of desperation, I've tried a few different separator characters. I was originally using "|", but I've also tried ";" and "#". It's set at "#" right now, and I've confirmed that none of these separator characters appear elsewhere in the document, and there is one separator at the end of each line.

I've been trying some more experiments. I think that some lines not containing variables is actually not the problem. I made a test document that has 4 lines, three with variables and one without, and it seems to work a little bit. Even when it does work, it takes a while to get the result, but most of the time I don't get a response from Nightbot at all. I have successfully gotten responses with and without variables though, so I don't think that's the issue.

And my full document works fine with a simple random selection program that isn't trying to parse variables.

It seems like even working with a text file that only has 4 lines is a big ask for this command, the way that it's written now. It works infrequently when the document is tiny, and I get a "[Response must be less than 400 characters]" error when the document is large. Maybe it's time to abandon this idea? Idunno.

I'm hoping that there's just something inefficient or wrong about the code for my command, which I adapted from the thread I linked in the OP without any programming knowledge myself; something about it seems to be throwing Nightbot for a loop.

I can't find the post now, but someone explained how to use gist in it
in your gist you should click on the RAW button and use that URL
example that I use for my deity command
All hail $(touser), the deity of $(eval p=$(urlfetch json https://gist.githubusercontent.com/leashadav/8e9291dfd972ecdedbc076c3e2c52660…).split(;); p[Math.floor(Math.random()*p.length)])

and then in the gist each new line needs to end with a ; except for the end of the file do not add the ;
example

Agriculture;
Air;
Animals;
Beauty

I use github for most of my commands cause pastebin keeps giving me problems. even tho github gist urls are so massive. I actually did control for that, and tried putting my document on other paste sites with shorter urls, but it didn't make a difference. So I think there's something wrong or subpar about my command code

Add json to the url when fetching the github link:

$(eval u='$(user)'; p=`$(urlfetch json https://gist.githubusercontent.com/webcamcals/78ee5273639b0cc5e72c4559b0d8f64d/raw/006d6e9d70f75e697bd31fefe5e12956714155a6/crystal)`.split(`#`); p[Math.floor(Math.random()*p.length)])

I would remove the # on the last line, since this might leave an empty entry at the end?

Gerhard said:
json

That did it!!! Thank you so much!! So embarrassed I forgot the "json" lmao I use that in like 100 commands 😓 Thankss

Didn't find your answer? The community is on Discord.

Ask on Discord