main file
const args = message.content.slice(prefix.length).trim().split(/ +/);
const stringSimilarity = require("string-similarity");
const pokemons = require('../../arrays/pokemons.js')
const poss = stringSimilarity.findBestMatch(args, pokemons)
console.log(poss.bestMatch.target)
arrays file
exports.pokemons = [
example1,
example2,
example3,
etc...
]
I am trying to get the closest name for the pokemon that the user inputs but I get this error Error: Bad arguments: First argument should be a string, second should be an array of strings and I am pretty sure that I did the arguments correct
There are two problems here.
The first is that you are exporting the array file as an object. This is what pokemons really is, since you set it as exports.pokemons:
{
pokemons: [
example1,
example2
]
}
You can destructure it:
const { pokemons } = require('../../arrays/pokemons.js')
And the second problem is that you are passing in the array of arguments. You probably just want the first argument. Remember arrays are 0-indexed and you made it start with the command so you have to get index 1 for the first argument
const poss = stringSimilarity.findBestMatch(args[1], pokemons)
As the error said that the findBestMatch is defined where first element is a string, but the args is surely array. Check your findBestMatch params again.