Get any Shlok with it's explaination from Bhagwat Gita. To use the `!gita` command, type `!gita` followed by a space and then the chapter number and shloka number separated by a space. For example, if you want to get the shloka and its meaning from Chapter 4, Verse 7 of the Bhagavad Gita, type `!gita 4 7`.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const content = context.params.event.content.split(' ');
const chapter = content[1];
const verse = content[2];
console.log(`Chapter: ${chapter}`);
console.log(`Verse: ${verse}`);
// Checking if chapter or shlok numbers are valid
try {
let geeta = await lib.http.request['@1.1.7'].get({
url: `https://bhagavadgitaapi.in/slok/${chapter}/${verse}/`,
});
let shlok = geeta.data.slok; // Fetching the Shlok
let tej = geeta.data.tej.ht; // Fetching it's meaning
let trans = geeta.data.siva.et; // Fetching English translation
try {
return await lib.discord.channels['@0.3.4'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: ``,
embed: {
title: `Chapter: ${chapter}, Verse: ${verse}`,
description: `**Shlok:**\`\`\`${shlok}\`\`\`\n\n**Explaination:** \`\`\`${tej}\`\`\``,
color: 0xfaafba,
footer: {
text: `English Translation:\n${trans}`,
},
},
message_reference: {
message_id: `${context.params.event.id}`,
},
});
} catch (e) {
return await lib.discord.channels['@0.3.4'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: ``,
embed: {
title: `Something went wrong...`,
description: `\`\`\`${e}\`\`\``,
color: 0xfaafba,
},
message_reference: {
message_id: `${context.params.event.id}`,
},
});
}
} catch {
return await lib.discord.channels['@0.3.4'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `Invalid chapter or verse number inputted. Kindly check them and try again.`,
message_reference: {
message_id: `${context.params.event.id}`,
},
});
}