Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

381
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!