Guide To Use Kitsu API For Creating Discord Bot 1

Guide To Use Kitsu API For Creating Discord Bot

Using different API is really fun for a developer and if you are also developer then you also enjoy the same thing. So, what about creating an anime command which gives the information of given anime. Before we get any further I shall tell you what is Kitsu. Kitsu is a modern anime discovery platform that helps you track the anime you’re watching, discover new anime and socialize with other fans.

REQUIRED PACKAGES

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

CHECKING ARGUMENTS

 if(!args.length) {
      return message.channel.send("Please Give Anime Name")
 }

DEFINING OPTIONS WITH REQUEST HEADER

   let option = {
      url: `https://kitsu.io/api/edge/anime?filter[text]=${args.join(" ")}`,
      method: `GET`,
      headers: {
        'Content-Type': "application/vnd.api+json",
        'Accept': "application/vnd.api+json"

      },
      json: true
    }
    

GIVING RESPONCE

  message.channel.send("Fetching The Info").then(msg => {
      get(option).then(body => {
       try {
        let embed = new MessageEmbed()
        .setTitle(body.data[0].attributes.titles.en)
        .setColor("RED")
        .setDescription(body.data[0].attributes.synopsis)
        .setThumbnail(body.data[0].attributes.posterImage.original)
        .addField("Ratings", body.data[0].attributes.averageRating)
        .addField("TOTAL EPISODES", body.data[0].attributes.episodeCount)
        //.setImage(body.data[0].attributes.coverImage.large)
        //try it
        
        
        message.channel.send(embed)
        msg.delete();
        
       } catch (err) {
        msg.delete();
         return message.channel.send("Unable to find this anime");
       }
        
        
        
      }  

You are done with creating Anime command, Basically I took some information from API and put it in embed and after that sended to channels.

Guide To Use Kitsu API For Creating Discord Bot 2

RESULTED CODE

Here is the resulted code – HERE

Leave a Reply

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