Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

388
Vistas
Error: Bad arguments: First argument should be a string, second should be an array of strings

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

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

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)
about 4 years ago · Juan Pablo Isaza Denunciar

0

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.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda