Random.cat Discord bot

时间:2017-08-13 10:21:57

标签: node.js discord discord.js

我想在我的discord bot中进行random.cat集成。使用下面的代码,我设法从http://random.cat/meow获取JSON。现在我想用message.channel.send发送图像,但我无法让它工作。有帮助吗? (真正的帮助,不是"下载一些猫并随机选择一个")

const Discord = require ("discord.js");
var request = require ("request");
const TOKEN = "Hidden"
const PREFIX = "`"
var cat = "http://random.cat/meow"

bot.on("message", function(message) {
if (message.author.equals(bot.user))return;

if (!message.content.startsWith(PREFIX)) return;

var args = message.content.substring(PREFIX.length).split(" ");

switch (args[0].toLowerCase()) {
    case "cat":
        request({
            url: cat,
            json: true
        }, function (error, response, body) {
            console.log(body);
        })
        break;
    }
});

bot.login(TOKEN)

1 个答案:

答案 0 :(得分:0)

尝试使用Fragment。在我的测试中出于某种原因,我在使用var cat = "http://random.cat/meow.php"时获得了406,虽然它修复了它。