Creating randomised command responses

Hi there everyone,

I’m sorry if this has been asked before, I’m sure it has. I’m new to NightBot, and I wanted to make some generated responses to a command. For instance, I do a lot of Pokemon Content on my channel. So I’d like to create a ‘Who’s that Pokemon command’, where if the viewer types !whosthatpokemon, Nightbot will choose from a series of other commands that will be descriptions of the pokemon.

For example !whosthatpokemon > !pikachu “This Pokemon can generate powerful electricity, within their cheek sacs that are extra soft and super stretchy”, but then if they type !whosthatpokemon again, it will choose a different description.

I’m not sure how to go about doing this or if its even possible.

Thank you for any help you can provide!

–TheeDrewGamer

Nightbot can only call one alias as far as I know, in that case this is not possible at the moment. You can instead do !whosthatpokemon random responses. There’s a lot of pokemons so it would be hard aswell to call alias, you would add tons of specific commands for them.

If you want to try the other method, idk if you already know it:

  1. Make a pastebin of the pokemons and their abilities/descriptions and add a ; after each one. Example:

Pikachu, example example example;
Charmander, example example example;
Squirtle, example example example;

and so on.

  1. Add this command and replace the YOURPASTEBINHERE with the /RAW/ version of the pastebin you created:

!addcom !whosthatpokemon It’s $(eval responses = $(urlfetch json YOURPASTEBINHERE).split(“;”); responses[Math.floor(Math.random() * responses.length)])

I hope I helped. :slight_smile:

1 Like

Hey @TheeDrewGamer!

What With_Vince suggested is the right direction. But I would like to expand a little bit on it since it seems you’re looking for the ability to do !whosthatpokemon pokemon as well as a random output if no query is specified. So here we go!

Create an account on Pastebin to be able to edit your paste in the future. Make sure the paste expiration date is set to never and I’d recommend setting the paste as unlisted.

In the paste type your Pokemon’s descriptions like the following example: put a ; (semi-colon) after each Pokemon name and at the end of every description except for the last one.

Pikachu; this Pokemon can generate powerful electricity, within their cheek sacs that are extra soft and super stretchy.;
AnotherPokemon; sorry, I don't know anything about Pokemon...;
LastPokemon; last description.

Then for the command it looks like this:

!addcom !whosthatpokemon $(eval p=`$(urlfetch json https://pastebin.com/raw/XXXXXXXX)`.split(`;`);q=decodeURIComponent(`$(querystring)`).toLowerCase();t=[];for(i=0;i<p.length;i++){t[i]=p[i].toLowerCase();}if(q){t.includes(q)?`${p[t.indexOf(q)]}:${p[t.indexOf(q)+1]}`:`Pokemon not recognized.`;}else{r=Math.floor(Math.random()*(p.length/2))*2;`${p[r]}:${p[r+1]}`;})

Replace XXXXXXXX in the command by your Paste ID.

1 Like

Oh wow that is fantastic, thank you so much for this Emily! I really appreciate you taking the time to show me how it works! This is a great help!

1 Like

Sorry for the delay with this Vince! I really appreciate you taking the time to respond and pointing me in the right direction with this!

1 Like

No problem! I’m glad we could help. :heart_eyes:

Sorry to keep bothering with this, I put in the command and when I tried it. It worked once, but now when I try it, nightbot comes back with undefined:undefinied. I’m guessing I’ve put in some text wrong somewhere, for it to come up with this?

Edit: I tried it again and it seems to be working occasionally but not all the time.

My bad, I haven’t tested it enough otherwise I would have found the error, it was an easy mistake, I fixed the code in my previous post.

1 Like

Oh my gosh you are a life saver! Thank you so much for doing that. It is working perfectly!

1 Like

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