Help with custom JS commands

Asked Aug 13, 2020·7 replies·Last activity 6 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

I'm trying to take a users text and change it to something else. I just dont fully understand the $eval() stuff. Here is what I have:

($eval var stringToAlter = 'test';var stringArray = stringToAlter.split('');var
alteredString;stringToAlter.forEach(s => { if (s % 2 === 0) { alteredString = alteredString +
s.toLowerCase(); } else { alteredString = alteredString + s.toUpperCase(); }});)

I'm trying to take the text and make every other word a capital letter to emulate the spongebob meme.

Thanks for any help!

7 replies

Well firstly is should be $(eval) , also it looks like s is undefined.
I can just write out something that should work for you If you want or feel free to problem solve yourself up to you.

Ok here this should work for your purposes

$(eval d="$(1)";a=`$(query)`.split(``);function Memify(a) {aOutput=``;for(b=0;b<a.length;b++) {c=Math.floor(b%2);if(c==0) {aOutput+=a[b].toUpperCase()} else {aOutput+=a[b].toLowerCase()}};return aOutput};d=="null"?"PlEaSe iNpUt sOmEtHiNg aFtEr !MeMe":Memify(a))

Hope this was helpful 🙂
Edit: Made it so if there is not input it explains the command.

Thank you sooooooooooooooo much! You are amazing

Hello again! I was just wondering if you could elaborate on some questions I have so I can code some others in the future without having to rely on help..

d="$(1)";
a=`$(query)`.split(``)

Can you tell me what $(1) does?
as well as the $(query)?

I'm guess they are parameters, but I can't find any documentation anywhere (I'm probably looking in the wrong spots) of what they mean and what they do...

Thanks again!

They are nightbot variables you can find them on the help docs..
$(query) takes everything said after the command and $(1) only takes the first word (or whenever the first space comes)
The reason I used the $(1) is to test whether it’s null or not (I tried with $(query) but it didn’t output null for some reason)
And $(query) is just take everything said and then splitting it into an array

OMG, this is perfect. Thank you so much for the elaboration and the helpful link!

Didn't find your answer? The community is on Discord.

Ask on Discord