Embedded XKCD

This commit is contained in:
Daniel Odendahl Jr
2017-05-25 18:00:11 +00:00
parent 61e5acce66
commit c22ec43fed
2 changed files with 14 additions and 6 deletions
+13 -5
View File
@@ -1,4 +1,5 @@
const { Command } = require('discord.js-commando');
const { RichEmbed } = require('discord.js');
const snekfetch = require('snekfetch');
module.exports = class XKCDCommand extends Command {
@@ -31,14 +32,21 @@ module.exports = class XKCDCommand extends Command {
try {
const current = await snekfetch
.get('https://xkcd.com/info.0.json');
if (type === 'today') return msg.say({ files: [current.body.img] })
.catch(err => msg.say(`${err.name}: ${err.message}`));
else {
if (type === 'today') {
const embed = new RichEmbed()
.setTitle(`${current.body.num} - ${current.body.title}`)
.setImage(current.body.img)
.setFooter(current.body.alt);
return msg.embed(embed);
} else {
const random = Math.floor(Math.random() * current.body.num) + 1;
const { body } = await snekfetch
.get(`https://xkcd.com/${random}/info.0.json`);
return msg.say({ files: [body.img] })
.catch(err => msg.say(`${err.name}: ${err.message}`));
const embed = new RichEmbed()
.setTitle(`${body.num} - ${body.title}`)
.setImage(body.img)
.setFooter(body.alt);
return msg.embed(embed);
}
} catch (err) {
return msg.say(`${err.name}: ${err.message}`);
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "21.1.0",
"version": "21.1.1",
"description": "A Discord Bot",
"main": "Shard.js",
"scripts": {