Add New Command gt - Game of Thrones Random Quotes

This commit is contained in:
Indrajith K L
2021-05-26 01:46:01 +05:30
parent 187e6bc1f2
commit 717a38d6b7
3 changed files with 50 additions and 0 deletions

17
.vscode/launch.json vendored Normal file
View File

@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\src\\main.js"
}
]
}

28
src/commands/gt.js Normal file
View File

@@ -0,0 +1,28 @@
const axios = require('axios').default;
const {MessageEmbed} = require('discord.js');
const instance = axios.create({
baseURL: 'https://game-of-thrones-quotes.herokuapp.com/v1'
});
async function getRandomQuotes(message, args) {
const randomQuotesUrl = "/random";
try {
const result = await instance.get(randomQuotesUrl);
const {sentence, character: {name, house: {name:houseName}}} = result.data;
const randomQuoteMessage = new MessageEmbed()
.setDescription(sentence)
.setFooter(`${name}, ${houseName}`);
message.channel.send(randomQuoteMessage);
} catch(error) {
const errorMessage = new MessageEmbed()
.setTitle("Something went wrong: Error getting quotes from Arya Stark")
.setColor("RED");
message.channel.send(errorMessage);
}
}
module.exports = {
execute(client, message, args) {
getRandomQuotes(message, args);
}
}

View File

@@ -24,6 +24,11 @@
"name": "vaccine", "name": "vaccine",
"description": "Get Vaccine Availability by Pincode", "description": "Get Vaccine Availability by Pincode",
"file": "./commands/vaccine.js" "file": "./commands/vaccine.js"
},
{
"name": "gt",
"description": "Game of Thrones Quotes",
"file": "./commands/gt.js"
} }
] ]
} }