NightDev Community Forums

Trying to pull random line from pastebin command. Help please?

Hi all!

I’m trying to make a !compliment command which will pull a random compliment from my pastebin link.

Here’s the code:

$(user), mate, you’re $(eval a=$(urlfetch json https://pastebin.com/raw/HyYaxkTf)"%22).split(","); a[Math.floor(Math.random()*a.length)])!

So, for example, it should turn out: thenoirman, mate, you’re a legend!

I’ve been trying to get it to work but it keeps coming back with “thenoirman, mate, you’re Unexpected identifier!” instead. Sadge. Anyone know what’s wrong?

Hey @thenoirman!

Pay attention to your quotes:

$(user), mate, you're $(eval a='$(urlfetch json https://pastebin.com/raw/HyYaxkTf)'.split(','); a[Math.floor(Math.random()*a.length)])!

You also already created the array in your Pastebin, the code above would work if the content of your paste was like this: some compliment, another compliment, the last compliment
Note that spliting with a comma isn’t the best option, because if your compliment contains a comma, it’ll be cut in half, prefer another character that’s never used in your list of elements.
With that said, since creating the array in the paste makes life harder, and that we want to avoid using the comma to split the compliments, I suggest you replace the content of your paste by the following:

a legend#
peng ya get me fam#
my mandem bruv#
an absolute geezer#
the reason I stream#
the bee’s knees#
my ride or die#
my favourite viewer#
who I dream of in my sleep#
why I wake up in the morning#
someone Id grab a pint with#
the best Gwent player I know#
more important to me than Gwent#
colder than Big Shaq#
better at Gwent than Pajabol#
better at drawing golds than Spyro#
better at mill than Bushy#	
better at deck-building than Myamon#
who Tailbot wishes he could beat#
the Cleaver to my Tunnel Drill#
the Jutta to my Eist#
the Snowdrop to my Morvran#
the Dandelion to my Geralt#
the Yghern to my Ozzrel#
the Lambert to my Eskel#
the Pavetta to my Duny

Which means the command will be like this:

$(user), mate, you're $(eval a='$(urlfetch json https://pastebin.com/raw/HyYaxkTf)'.split('#'); a[Math.floor(Math.random()*a.length)])!

Thanks so much for responding, Emily! Really appreciate it. Before you responded, I was tinkering some more and managed to get it to work with this code:

$(user), mate, you’re $(eval a = "$(urlfetch json https://pastebin.com/raw/FAEtRYU5 )".split(","); a[Math.floor(Math.random() * (a.length - 1))];)!

To be honest, I don’t know coding at all or Javascript but this worked for some reason. BUT… I’ve got a bit of a new problem now. For some reason the command responds very slowly or doesn’t work sometime. You wouldn’t happen to know what would be the reason?

Ok firstly the -1 in your command is technically unnecessary and is making it impossible to get the last result in the pastebin.

As for the not responding that’s most likely due to high cooldown and the delay you probably can’t do anything about and could be due to whatever $(eval) is hosted in being slow at the time.

Super cool. Really grateful for the help and response!

1 Like