As we are dealing with very dangerous virus whose name is corona virus and you can call it Covid19, It will be very Great if you can make command on it which tells you live count of cases. i will be using my command handler and if you do not know how to create command handler than you should check this post – COMMAND HANDLER
we will be using novelcovid , install it by using npm install novelcovid
const discord = require("discord.js") const { NovelCovid } = require("novelcovid"); const track = new NovelCovid(); module.exports = { name: "corona", category: "info", description: "Get the stats of corona", usage: "corona all or corona <country>", aliases: ["covid", "covid19"], run: async (client, message, args) => { } }
First we will be adding error argument if there is no args are given
if(!args.length) { return message.channel.send("Please give the name of country") }
Now first we will add argument 1 in which if user type !corona all then it will display global cases information
if(args.join(" ") === "all") { let corona = await track.all() //it will give global cases let embed = new discord.MessageEmbed() .setTitle("Global Cases") .setColor("#ff2050") .setDescription("Sometimes cases number may differ from small amount.") .addField("Total Cases", corona.cases, true) .addField("Total Deaths", corona.deaths, true) .addField("Total Recovered", corona.recovered, true) .addField("Today's Cases", corona.todayCases, true) .addField("Today's Deaths", corona.todayDeaths, true) .addField("Active Cases", corona.active, true); return message.channel.send(embed) }
As it will send global cases information in channel

As we added global report , now time to add report based on countries by using else
else { let corona = await track.countries(args.join(" ")) //change it to countries let embed = new discord.MessageEmbed() .setTitle(`${corona.country}`) .setColor("#ff2050") .setDescription("Sometimes cases number may differ from small amount.") .addField("Total Cases", corona.cases, true) .addField("Total Deaths", corona.deaths, true) .addField("Total Recovered", corona.recovered, true) .addField("Today's Cases", corona.todayCases, true) .addField("Today's Deaths", corona.todayDeaths, true) .addField("Active Cases", corona.active, true); return message.channel.send(embed) }
You are done with this simple command

Table of Contents
Resulting Code
here is the link of resulting code – HERE
One Comment
Leave a Reply