mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-25 06:42:51 +02:00
Embedded XKCD
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
const { Command } = require('discord.js-commando');
|
const { Command } = require('discord.js-commando');
|
||||||
|
const { RichEmbed } = require('discord.js');
|
||||||
const snekfetch = require('snekfetch');
|
const snekfetch = require('snekfetch');
|
||||||
|
|
||||||
module.exports = class XKCDCommand extends Command {
|
module.exports = class XKCDCommand extends Command {
|
||||||
@@ -31,14 +32,21 @@ module.exports = class XKCDCommand extends Command {
|
|||||||
try {
|
try {
|
||||||
const current = await snekfetch
|
const current = await snekfetch
|
||||||
.get('https://xkcd.com/info.0.json');
|
.get('https://xkcd.com/info.0.json');
|
||||||
if (type === 'today') return msg.say({ files: [current.body.img] })
|
if (type === 'today') {
|
||||||
.catch(err => msg.say(`${err.name}: ${err.message}`));
|
const embed = new RichEmbed()
|
||||||
else {
|
.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 random = Math.floor(Math.random() * current.body.num) + 1;
|
||||||
const { body } = await snekfetch
|
const { body } = await snekfetch
|
||||||
.get(`https://xkcd.com/${random}/info.0.json`);
|
.get(`https://xkcd.com/${random}/info.0.json`);
|
||||||
return msg.say({ files: [body.img] })
|
const embed = new RichEmbed()
|
||||||
.catch(err => msg.say(`${err.name}: ${err.message}`));
|
.setTitle(`${body.num} - ${body.title}`)
|
||||||
|
.setImage(body.img)
|
||||||
|
.setFooter(body.alt);
|
||||||
|
return msg.embed(embed);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return msg.say(`${err.name}: ${err.message}`);
|
return msg.say(`${err.name}: ${err.message}`);
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiaobot",
|
"name": "xiaobot",
|
||||||
"version": "21.1.0",
|
"version": "21.1.1",
|
||||||
"description": "A Discord Bot",
|
"description": "A Discord Bot",
|
||||||
"main": "Shard.js",
|
"main": "Shard.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user