random fact command not working

Hi! I’m a mod trying to add a random fact command to chat and I’ve searched through quite a few topics here trying to fix the issue I’m having with Nightbot in an attempt to create a random fact command. When I attempt to use it, I’m getting back the message ‘Unexpected identifier’. I originally had backticks and commas in my pastebin from the first post I came across and thought maybe that was it so I removed those and added ;. I then switched from ; to |. I’ve used the following:

!addcom -cd=5 !truefacts $(eval a=$(urlfetch json https://pastebin.com/raw/Wa8xp70R);a[Math.floor(Math.random()*a.length)])
!addcom -cd=5 !squidfacts $(eval a=`$(urlfetch json https://pastebin.com/raw/Wa8xp70R)`.split(`|`); a[Math.floor(Math.random()*a.length)])
!addcom -cd=5 !squidfacts $(eval facts= "$(urlfetch json https://pastebin.com/raw/Wa8xp70R)".split(";"); facts[Math.floor(Math.random() * (facts.length - 1))])

This last one I did not use after switching to |. Would the " vs ’ in split change anything because of my use of single ’ in my facts? I’m genuinely a fish out of water when it comes to a lot of coding.

Thank you for any help you can provide!

Hey @catbutts!

Your second command should work, but you put backticks ` in your Pastebin so it’s breaking your code, simply remove them or replace them with regular apostrophes ' if needed:
230302113258

I just looked through my pastebin! I genuinely have no idea how those got there or even why they’re there? Thank you so much for noticing them! I thought I was losing my mind from all of the attempts I had made trying to add this because I knew I had followed all the steps correctly. I took them out and gave it another try, it works now!! Thank you so much.

1 Like

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