Everytime you say '-search', you have a 20% chance of discovering a pokemon, and seeing its species_id, height, weight and base experience.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const pokemon = require('pokemon');
const encounter = Math.random() * 100;
const randpokemon = pokemon.random();
const Pokedex = require('pokedex');
const pokedex = new Pokedex();
let x = 'a';
if (
randpokemon.charAt(0) === 'A' ||
randpokemon.charAt(0) === 'E' ||
randpokemon.charAt(0) === 'I' ||
randpokemon.charAt(0) === 'U' ||
randpokemon.charAt(0) === 'O'
) {
x = 'an';
}
let entry = pokedex.pokemon(randpokemon.toLowerCase());
let timeout = await lib.utils.kv['@0.1.16'].get({
key: `timeout`,
defaultValue: false,
});
if (context.params.event.content.startsWith('-search')) {
if (!timeout) {
if (encounter <= 20) {
await lib.discord.channels['@0.1.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Wow, you encountered a **POKèMON!** It's ${x} **${randpokemon}**`,
tts: false,
embed: {
type: 'rich',
title: 'Pokèdex Entry',
description: '',
color: 0xff4400,
image: {
url: entry.sprites.animated,
},
fields: [
{
name: 'ID',
value: `${entry.id}`,
},
{
name: 'Height',
value: `${entry.height}`,
},
{
name: 'Weight',
value: `${entry.weight}`,
},
{
name: 'Base Experience',
value: `${entry.base_experience}`,
},
],
},
});
await lib.utils.kv['@0.1.16'].set({
key: `timeout`,
value: true,
ttl: 5,
});
} else {
await lib.discord.channels['@0.1.2'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Unfortunately you didn't find any POKèMON.`,
});
}
} else {
await lib.discord.channels['@0.1.2'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `You have to wait 5 seconds between each use of this command.`,
});
}
}