I am trying to make a command that fetches some json, this part works.
I would like to check if the query successfully fetches json before proceding, so that chat doesn't get spammed with unexpected identifier (thanks for ruining this combination of 2 words for me btw LUL)
Here's what I have so far:
!addcom !pokemove $(evallet apitest = `$(urlfetch json https://pokeapi.co/api/v2/move/$(query))`;`${apitest}`.includes(`Server`) ? `Please use - instead of space or a real move FeelsOkayMan` : apitest;let api = $(urlfetch json https://pokeapi.co/api/v2/move/$(query));`${api["name"]} : ${api["power"]} pow ${api["accuracy"]} acc ${api["damage_class"]["name"]} ${api["type"]["name"]}`;)
Line 2 sets a the response as a string
Line 3 checks the string for the substring "Server" (if the response is an error it contains "Remote Server Returned Code 404" as a string, not json) and if it does contain that substring it sends the error message "Please use - instead of space or a real move FeelsOkayMan"
Line 4 sets the response as a urlfetch response object.
Line 5 returns the information required from the response.
Here is the actual and expected behaviour:
Input 1
!pokemove draco-meteor
Expected
draco-meteor : 130 pow 90 acc special dragon
Actual
draco-meteor : 130 pow 90 acc special dragon
Input 2
!pokemove draco meteor
Expected
Please use - instead of space or a real move FeelsOkayMan
Actual
Unexpected identifier
Input 3
!pokemove hyper-beam
Expected
hyper-beam : 150 pow 90 acc special normal
Actual
hyper-beam : 150 pow 90 acc special normal
Input 4
!pokemove hyper beam
Expected
Please use - instead of space or a real move FeelsOkayMan
Actual
Unexpected identifier