Searching for an array Entry from Urlfetch saved in array

Hey!

Im new to this Forum and I havent found any Question or Answer that can help me.

I want to do a !me command that responds to the user that calls it.
I am able to urlfetch a raw pastebin document and save it in an array, with each line being split accordingly with a split char (§ in my case).
Now i want to iterate this array and no matter what I do, i alway get “Right hand side of ‘instanceof’ is not an object”.
FeelsBadMan.

Here is my code:

$(eval var a = "$(urlfetch https://pastebin.com/raw/CU40yg5v)".split("§"); 
var user = "$(user)"; 
for(int i = 0; i < a.length; i++){ 
if(a[i].startsWith(user)){ 
a[i].split(":")[1]; }}})

I cant get it to work. Can anyone give me a hint on what im doing wrong?

Looks like you want Nightbot to search through the array and look for whatever item matches the user’s name, then output the phrase associated with the name (ie. it should output ‘cmonBruh’ for Craktil), so I edited the code such that it’ll output some error message if it fails to find a username in the array:

!editcom !me $(eval a='$(urlfetch json https://pastebin.com/raw/CU40yg5v)'.split('§');b='';for(i=0;i<a.length;i++){if(a[i].startsWith('$(user)')){b=a[i].split(':')[1];}}if(b==''){b='Search failed! rooShrug';}b;)

The error message is ‘Search failed! rooShrug’. You can change that to whatever you want.

1 Like

My friend, I do not know how you achieved this where I so miserably failed. Thank you very much for your quick help!

Im sorry if I didn’t phrase my question correctly. English is not my first language.

Thank you again for your help!

cheers, Craktil.

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