urlfetch error: code generation from strings disallowed for this context

I am trying to do a simple pastebin url fetch for an !affirmation commands that gives random affirmations. I am getting the ‘Code generation from strings disallowed for this context’ every time I enter in the command. Any suggestions?

$(eval a=$(urlfetch json Affirmations - Pastebin.com);a[Math.floor(Math.random()*a.length)])

$(eval let to=’$(touser)’,a=$(urlfetch json https://pastebin.com/raw/WK2Ahtac); a[Math.floor(Math.random()*a.length)])

I’ll remove the file so Please copy the pastebin content to your pastebin and use that

Hey @sssloannn!

It doesn’t work because you’re not using the raw version of the Pastebin, and it won’t work for two other reasons:

  1. you need to turn your Pastebin into an array, we’ll use .split().
  2. Nightbot can’t read the variables in a Pastebin if they’ve not been defined first.

With that in mind, here’s a fix:

$(eval t=`$(touser)`; a=`$(urlfetch json https://pastebin.com/raw/JjJuPB6R)`.split(`;`); a[Math.floor(Math.random()*a.length)])

And inside your Pastebin replace all the instances of ${touser} with ${t}.

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