Creating Pokedex Command for Discord Bot Using API and discord.js v12 1

Creating Pokedex Command for Discord Bot Using API and discord.js v12

In this post I am going to show you Creating Pokédex Command for Discord Bot Using API and discord.js v12, as you guys know Pokémon is very famous anime and it is very interesting to watch but have you ever thought that we can make command for bot based on pokedex, by using it you can have given Pokémon image and description about the Pokémon. So lets start to developing without wasting any time.

We will be using this link to fetch Pokémon information – https://courses.cs.washington.edu/courses/cse154/webservices/pokedex/pokedex.php?pokemon=

We will be using arguments to get the text from the author and if you don’t know what is argument and how to use it then check out this document – ARGUMENTS

const options = {
  url: `https://courses.cs.washington.edu/courses/cse154/webservices/pokedex/pokedex.php?pokemon=${args.join(" ")}`,
  json: true
  
}

Before we go any further I shall tell you we will be using request-promise-native to fetch data from API so you should define it first.

const { get } = require("request-promise-native");
const { MessageEmbed } = require("discord.js")

We will let the bot send the message of waiting then fetch information of given Pokémon from API after we get we will be showing it in embed by using MessageEmbed.

message.channel.send("Fetching Informtion for API").then(msg => {
  get(options).then(body => {
    
    let embed = new MessageEmbed()
    .setAuthor(body.name, `https://courses.cs.washington.edu/courses/cse154/webservices/pokedex/${body.images.typeIcon}`)
    .setDescription(body.info.description)
    .setThumbnail(`https://courses.cs.washington.edu/courses/cse154/webservices/pokedex/${body.images.photo}`)
    .setColor("#ff2050")
    .setFooter(`Weakness of pokemon - ${body.info.weakness}`, `https://courses.cs.washington.edu/courses/cse154/webservices/pokedex/${body.images.weaknessIcon}`)
    
    message.channel.send(embed)
    msg.delete()
  })
})

Output

Creating Pokédex Command for Discord Bot Using API and discord.js v12

Result Code

Here is the result code of post – HERE

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *