This endpoint lets you see a country's basic information. Just run !countryinfo and you'll see the country's flag, capital, continent, population, and more!
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
let name = context.params.event.content.split(' ').slice(1).join(' ');
if (!name) {
return await lib.discord.channels['@0.3.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: '',
tts: false,
embeds: [
{
type: 'rich',
title: `Error`,
description: `You need to mention a country to gather info on.\n**Example:** \`!countryinfo usa\``,
color: 0xff006a,
},
],
});
}
let country = await lib.http.request['@1.1.6'].get({
url: `https://restcountries.com/v3.1/name/${name}`,
});
console.log(country);
console.log(country.data[0]);
if (country.statusCode === 404) {
return await lib.discord.channels['@0.3.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: '',
tts: false,
embeds: [
{
type: 'rich',
title: `Error`,
description: `Country not found. Maybe you misspelled something.`,
color: 0xff006a,
},
],
});
}
await lib.discord.channels['@0.3.0'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: '',
tts: false,
embeds: [
{
type: 'rich',
title: `${country.data[0].flag} | ${country.data[0].name.official}`,
description: `Information about ${country.data[0].name.common}\n`,
color: 0xff006a,
fields: [
{
name: `Continent`,
value: `${country.data[0].continents[0]}`,
},
{
name: `Population`,
value: `${country.data[0].population}`,
},
{
name: `Capital`,
value: `${country.data[0].capital[0]}`,
},
{
name: `Timezones`,
value: `\`${country.data[0].timezones}\``,
},
{
name: `Independency`,
value: `${country.data[0].independent}`,
},
{
name: `Start of Week`,
value: `${country.data[0].startOfWeek}`,
},
],
footer: {
text: `Coat of Arms`,
icon_url: `${country.data[0].coatOfArms.png}`,
},
},
],
});