I would like to set up a !truefacts command where anyone can use it and the community will receive random facts back! I'm trying to set up 44 commands! Is it doable? Or is it too much words for Nightbot? If doable, how can I set up the command? Please help! Thank you!
How to set up !truefacts command with Nightbot!
15 replies
Here is my pastebin. I hope this works!
If this helps, here is what I wrote for the !truefacts command:
$(eval a=[urlfetch https://pastebin.com/raw/TM7SdKDi];a[Math.random()*a.length])
Maybe I'm doing this wrong! Dx It keeps saying "Unexpected Identifier."
I never managed to make a Pastebin containing an array work, it's always broken for some reason...
So my fix suggestion is the following, something that proved to work reliably over the years:
Pastebin:
Fact #1 Lorem ipsum dolor sit amet, consectetur adipiscing elit.|Fact #2 Morbi convallis lacinia ipsum.|Fact #3 Nulla eget metus a nisl lobortis tincidunt.|...Fact #n-1 Maecenas arcu sem, ultricies eu ultricies sit amet, porta non enim.|Fact #n Vestibulum aliquet justo tellus.
There's no error, the last one doesn't end with a | (vertical bar).
Command:
$(eval a=`$(urlfetch json https://pastebin.com/raw/XXXXXXXX)`.split(`|`); a[Math.floor(Math.random()*a.length)])
You could even automate the fact-numbering process, just put your facts without the numbers and modify the command like this:
Pastebin:
Lorem ipsum dolor sit amet, consectetur adipiscing elit.|Morbi convallis lacinia ipsum.|Nulla eget metus a nisl lobortis tincidunt.|...Maecenas arcu sem, ultricies eu ultricies sit amet, porta non enim.|Vestibulum aliquet justo tellus.
Command:
$(eval a=`$(urlfetch json https://pastebin.com/raw/XXXXXXXX)`.split(`|`); r=Math.floor(Math.random()*a.length); `Fact #${r+1} ${a[r]}`)
And if you want to be able to call a specific fact by its number, you can modify the previous command this way:
$(eval q=`$(query)`; a=`$(urlfetch json https://pastebin.com/raw/XXXXXXXX)`.split(`|`); r=Math.floor(Math.random()*a.length); if(q>0 && q<=a.length){r=q-1} `Fact #${r+1} ${a[r]}`)
Didn't find your answer? The community is on Discord.
Ask on Discord