Search your favourite pokemon
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const axios = require('axios');
if (context.params.event.content.startsWith('!pokemon')) {
const args = context.params.event.content.split(' ').slice(1);
if (!args.length)
return lib.discord.channels['@0.1.2'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `You need to give pokemon name.`,
});
const {data} = await axios(
'https://pokeapi.co/api/v2/pokemon/' +
encodeURIComponent(args.join('-').toLowerCase())
);
if (!data)
return lib.discord.channels['@0.1.2'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Something went wrong :/`,
});
await lib.discord.channels['@0.1.2'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: ``,
embed: {
color: 0xffff00,
title: data.name[0].toUpperCase() + data.name.slice(1) + ' | ' + data.id,
image: {
url: `https://play.pokemonshowdown.com/sprites/ani/${data.name
.split(' ')
.join('-')}.gif`,
},
thumbnail: {url: data.sprites.front_default},
description: `**${data.name}** is ${data.types
.map((x) => `\`${x.type.name}\``)
.join(', ')} type pokemon.`,
fields: [
{
name: 'Ability',
value: data.abilities.map((x) => `\`${x.ability.name}\``).join(', '),
inline: true,
},
{name: 'Weight (Kg)', value: data.weight, inline: true},
{
name: 'Moves',
value:
data.moves
.filter((x, i) => i < 3)
.map((x) => `\`${x.move.name}\``)
.join(', ') +
(data.moves.length > 3
? `\n**+ ${data.moves.length - 3} more**`
: ''),
},
],
},
});
}