Need help with a command that checks a query to output different responses

I’m trying to make a command that runs something like this:

!command (without option) → asks if option1 or option2

!command option1 → outputs sentence1
!command option2 → runs $(eval Math.floor(Math.random() * X) == 0 ? “sentence2” : “Sentence 3”

So if the random number is 0 it does sentence2 if its any other number it does sentence 3

I’ve gotten all the code to work indepedently but I can’t seem to get the format right when I combine everything together.

I have it set up like this. I’m not exactly sure what I’m doing wrong.

$(eval a=$(query).toLowerCase();a.includes(‘option1’) ? ‘sentence1’;a.includes(‘option2’) ? $(eval Math.floor(Math.random() * X) == 0 ? “sentence 2” : “sentence 3”; ‘option1 or option2’)

X is a number that put in.

Hey @mortalpixel!

I’d say you’re not too far off, I’ll write it a bit differently tho’:

$(eval q = '$(query)'.toLowerCase(); r = Math.floor(Math.random() * X); o = 'Please rerun the command with either OPTION_1 or OPTION_2'; if (q.includes('OPTION_1')) {o='SENTENCE_1'} if (q.includes('OPTION_2')) {r === 0 ? o = 'SENTENCE_2' : o = 'SENTENCE_3'} o;)

Right now, if the entry contains both OPTION_1 and OPTION_2 (regardless of the order they’re in), the code favors OPTION_2, add an else before the second if to favor OPTION_1 instead.

The ternary operator is fun and all, but sometimes good old ifs make the code easier to read and debug.

2 Likes

Thanks for the help I just couldn’t figure out how to get this to work. I didn’t think you could put two ifs like that.

1 Like

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