From bdc1d69a7985d69c233ec3fbda30221359b9b282 Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sun, 17 Jan 2021 23:28:05 -0500 Subject: [PATCH] More ways to match country name --- commands/search/country.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/commands/search/country.js b/commands/search/country.js index adb30df4..9e2f4978 100644 --- a/commands/search/country.js +++ b/commands/search/country.js @@ -32,7 +32,12 @@ module.exports = class CountryCommand extends Command { async run(msg, { query }) { try { const { body } = await request.get(`https://restcountries.eu/rest/v2/name/${query}`); - const data = body.find(country => country.name.toLowerCase() === query.toLowerCase()) || body[0]; + const data = body.find(country => { + return country.name.toLowerCase() === query.toLowerCase() + || country.altSpellings.some(alt => alt.toLowerCase() === query.toLowerCase()) + || country.alpha2Code.toLowerCase() === query.toLowerCase() + || country.alpha3Code.toLowerCase() === query.toLowerCase() + }) || body[0]; const embed = new MessageEmbed() .setColor(0x00AE86) .setTitle(data.name)