0
votes

I want to make a random.cat integration in my discord bot. With code below i managed to get the JSON from http://random.cat/meow. Now i want to send the image with message.channel.send, but i can't get it to work. Any help? (Real help, not "download some cats and make a random picker")

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
I don't see where you tried sendingWright
I tried with exporting body to a value and changing file to attachment... I thought that's the correct way. Solved by doing message.channel.send(body).Kriss7475
Does it log the URL to your console when the command is run?Kae
Here's the whole codeKriss7475
case "cat": console.log("["+date + "] "+msg.author.username +"#"+ msg.author.discriminator + " UID "+ msg.author.id +" called "+ args[0] +" Server: " + msg.guild.name.toString() + ". Channel: #" + msg.channel.name.toString() + "." ) request({ url: cat, json: true }, function (error, response, body) { msg.channel.send("Your cat will load in a few seconds, " + msg.author.toString() + "." ) msg.channel.send(body) }) break;Kriss7475

1 Answers

0
votes

Try using var cat = "http://random.cat/meow.php". In my testing for some reason I was given a 406 when using http://random.cat/meow though that fixed it.