Reputation: 39
I am trying to put a cursed image command in my discord.js bot but it keeps coming up with this error
got('https://www.reddit.com/r/madlads/random/.json').then(response => {
^
ReferenceError: got is not defined
Here is the code
if(command === "cursed") {
got('https://www.reddit.com/r/cursedimages/random/.json').then(response => {
let content = JSON.parse(response.body);
var image = content[0].data.children[0].data.url;
let permalink = content[0].data.children[0].data.permalink;
let memeUrl = `https://reddit.com${permalink}`;
let memeImage = content[0].data.children[0].data.url;
let memeTitle = content[0].data.children[0].data.title;
let memeUpvotes = content[0].data.children[0].data.ups;
let memeNumComments = content[0].data.children[0].data.num_comments;
const cursedembed = new Discord.MessageEmbed()
.setColor('RANDOM')
.setTitle(content[0].data.children[0].data.title)
.setURL(`${memeUrl}`)
.setImage(image)
.setFooter(`👍 ${memeUpvotes} 💬 ${memeNumComments}`)
.setTimestamp()
message.channel.send(cursedembed);
});
}
Upvotes: 0
Views: 179
Reputation: 2145
Since you don't have node-fetch
as one of your packages, you won't be able to use the fetch
function. In order to use this package, you'll have to follow three steps.
node-fetch
. This can be done by running npm i node-fetch
in your project directory.node-fetch
into your code. This can be done by having const fetch = require('node-fetch');
at the top of your code file, similar to your discord.js import.got
with fetch
.After that, you should be able to use fetch
in order to download web content and post reddit content on discord.
Upvotes: 1