help needed with random response command

Hey there, im trying to create a custom command for my channel. It’s a pick 5 random names command.

i was able a make a version where it picked one, but i want to increase it where it picks 5 names at once instead. i tried repeating the code 5 times in the command but it was too long. is this possible?

this is my pick command:

!addcom !pick /me picks... $(eval a="$(urlfetch json https://pastebin.com/raw/Wi7qKhqa)".split(",");a[Math.floor(Math.random()*a.length)]) ... you're welcome Kappa -cd=5

i have it picking from a custom list i made in pastebin

Hey @rello32!

First we’ll need to fix your paste, because otherwise you’re going to have issues down the line, it’ll also allow us to remove the .split(), it’s not needed.
If you want to keep the current shape of it, all you need to do is to replace the backticks ` with double quotes: ", you can easily do so with your notepad, use the Find and Replace feature. In the end, it should look like this:

["NAME_1",
"NAME_2",
// ...
"LAST_NAME"]

:warning: there’s a quote missing on line 224 of your paste, make sure to add it.

I also assume you want to avoid duplicates, so here’s how to write such command:

!addcom !pick $(eval names = $(urlfetch json https://pastebin.com/raw/XXXXXXXX); pickedNames = Array.from({ length: 5 }, e => names.splice(Math.floor(Math.random() * names.length), 1).toString()); `/me picks... ${pickedNames.join(', ')} ... you're welcome Kappa`;)
1 Like

Thank you so much. I did the changes as you suggested into a new paste so i can see the difference, and it works like a charm. I also noticed i can change { length: 5 } to adjust the number of picks I want. Thanks again, amazing work.

1 Like

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