I'm trying to create a !Riddle based on a custom list of Riddles I create. I will put them in Pastebin. I've seen someone has done this, and I was curious how they are able to get it to use 2 commands (!riddle and !answer) to pull the correct info from the same file. I guess I don't understand the necessary formatting for the file. Any Help?
If you need further help with the command itself let me know.
Purple Wolf
Hey man i was wondering how you would go about coding something like this as i don't have much knowledge in how to programming nightbot and things like this using two separate command and im still trying to learn as much as i can 😅
Quirky Fox
Wel firstly have to made a pastebin of all the riddles you want?
Well you don’t need to have “Riddlex” it should be Riddle3 that was just and example I posted earlier. Also for the answer to the last one it should just be two. As long answers aren’t hard to guess
Purple Wolf
Alright i have changed that now to riddle3 and two
Quirky Fox
Here’s the command:
$(eval RiddleList=$(urlfetch json https://pastebin.com/raw/Xw5kc5E8);`$(3)`!=`null`?`To many arguments given.`:`$(1)`==`null`?`Please choose a riddle 1-31 and type the answer after it.`:`$(2)`==`null`&&parseInt(`$(1)`)<=31&&parseInt(`$(1)`)>=1?RiddleList.Riddle$(1).Riddle:parseInt(`$(1)`)<1||parseInt(`$(1)`)>31?`Sorry riddle “$(1)” does not exist.`:`$(2)`.toLowerCase()==RiddleList.Riddle$(1).Answer.toLowerCase()?`Correct!!!`:`Wrong :/`)
Add this trough the dashboard it won’t send through chat. Also get rid of the “RiddleList=” at the very begging (In the pastebin)
Btw the last answer is mistyped. And riddle 10 is blank.
Purple Wolf
Thanks man ive corrected those two riddles, removed the "riddlelist=" and i added it through nightbot dashboard. Though it comes up with unexpected string if i leave the "{}" around all the riddles in pastebin but if i remove them it comes up with "unexpected token ':' "
Polar Cat
Hey @Purple Wolf!
Before we start, your JSON file presents many errors—mostly missing commas, that's the reason why you get the error, so please copy/paste the correction I made of it (expires in 2 weeks). Also, riddle #15 was missing, so you have 30 riddles, not 31.
Then @Quirky Fox if I may, I recommend using the following syntax to navigate through a JSON if you're going to have a dynamic variable to reach an element: ``RiddleList[Riddle${var}].Riddle``
Finally, I rewrote the command by simplifying it a bit, and making sure that "answer" would evaluate to correct as well as "an answer" or "a very long answer" as it wasn't the case.
else{`Please choose a riddle (1 → 30). To submit an answer, specify the riddle number, then your answer.`}
Here's the command for a quick copy/paste, make sure to replace XXXXXXXX with your paste ID:
$(eval RiddleList=$(urlfetch json https://pastebin.com/raw/XXXXXXXX);q=`$(query)`.split(` `);if(q.length>=1&&!isNaN(q[0])&&q[0]>0&&q[0]<=30){if(q.length==1){RiddleList[`Riddle${q}`].Riddle;}else{n=q.shift();RiddleList[`Riddle${n}`].Answer.toLowerCase().includes(q.join(` `).toLowerCase())?`Correct!!!`:`Wrong :/`;}}else{`Please choose a riddle (1 → 30). To submit an answer, specify the riddle number, then your answer.`})
Purple Wolf
Thanks heaps Potatoeaterlove and Emily
it works now i think it was mainly an issue with the way the pastebin was set up, but it works perfectly now. I thank you guys for your help 😁
Maple Goose
Ahh.. this topic still in debate .. bro me too use riddles like games in my stream recommend you to use this.
JUST COPY PASTE THESE LINES IN YOUR STREAM CHAT. It will work.