mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-05 13:53:12 +02:00
Fix strange error in pokedex fetch
This commit is contained in:
@@ -41,6 +41,7 @@ module.exports = class PokedexCommand extends Command {
|
||||
async run(msg, { pokemon }) {
|
||||
try {
|
||||
const data = await this.client.pokemon.fetch(pokemon);
|
||||
if (!data) return msg.say('Could not find any results.');
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0xED1C24)
|
||||
.setAuthor(`#${data.displayID} - ${data.name}`, data.boxImageURL, data.serebiiURL)
|
||||
|
||||
@@ -6,6 +6,7 @@ const missingno = require('../../assets/json/missingno');
|
||||
module.exports = class PokemonStore extends Collection {
|
||||
async fetch(query) {
|
||||
query = encodeURIComponent(query.toLowerCase().replace(/ /g, '-').replace(/[^a-zA-Z0-9-]/g, ''));
|
||||
if (!query) return null;
|
||||
const num = Number.parseInt(query, 10);
|
||||
if (this.has(num)) return this.get(num);
|
||||
const found = this.find(pokemon => pokemon.slug === query);
|
||||
@@ -15,9 +16,13 @@ module.exports = class PokemonStore extends Collection {
|
||||
this.set(pokemon.id, pokemon);
|
||||
return pokemon;
|
||||
}
|
||||
const { body } = await request.get(`https://pokeapi.co/api/v2/pokemon-species/${query}/`);
|
||||
const pokemon = new Pokemon(body);
|
||||
this.set(pokemon.id, pokemon);
|
||||
return pokemon;
|
||||
try {
|
||||
const { body } = await request.get(`https://pokeapi.co/api/v2/pokemon-species/${query}/`);
|
||||
const pokemon = new Pokemon(body);
|
||||
this.set(pokemon.id, pokemon);
|
||||
return pokemon;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user