Hey everyone! I’m working on a Discord bot that shows random cat pictures. I’ve managed to get the JSON data from an API, but I’m stuck on how to send the image in a Discord channel. Here’s what I’ve got so far:
const Discord = require('discord.js');
const axios = require('axios');
const bot = new Discord.Client();
const PREFIX = '!';
const CAT_API = 'https://api.thecatapi.com/v1/images/search';
bot.on('message', async (message) => {
if (message.author.bot || !message.content.startsWith(PREFIX)) return;
const command = message.content.slice(PREFIX.length).toLowerCase();
if (command === 'kitty') {
try {
const response = await axios.get(CAT_API);
console.log(response.data);
// How do I send the image to the channel?
} catch (error) {
console.error('Error fetching cat image:', error);
}
}
});
bot.login('YOUR_BOT_TOKEN');
Can anyone help me figure out how to send the image using message.channel.send()? I’d really appreciate some guidance on this! Thanks in advance!