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?
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
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
$(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.
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 ‘:’ "
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 @potatoeaterlove 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.
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.`}
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.`})