I am trying to make a program for a Discord bot that takes a single parameter that the user gives it, checks to make sure the parameter is valid and usable, then sends it to the Merriam Webster API, takes the JSON it gets back and displays the short definition to the end user.
The only part I need an answer for right now is how would I check to make sure that the argument the user gives me is actually a valid word, or is that even possible? I know how to check to make sure the argument the user supplies is actually a bunch of letters with args[0].split("").every(isNaN)
, but not how to verify it is a word before sending it off. I believe the api handles it well either way, instead it will just return search results that it thinks might be what the user was trying to search for, except this will make the code more complicated, because I will have to make sure the definition was actually included in the response.
Searched all over, all I got was how to see if a string contained a certain word or phrase. I am using https://dictionaryapi.com.