Problem with Reddit API

When I run the /meme command, the console replies Unexpected token '<', "<!doctype "... is not a valid JSON (PS: I use a hosting company) Here's my meme.js const { EmbedBuilder } = require('discord.js'); module.exports = { name: 'meme', description: 'Donne un meme!', callback: async (client, interaction) => {
async function meme() { try { const response = await fetch('https://www.reddit.com/r/memes/random/.json'); const memeData = await response.json(); const title = memeData[0].data.children[0].data.title; const image = memeData[0].data.children[0].data.url; const author = memeData[0].data.children[0].data.author; const embed = new EmbedBuilder() .setColor("Random") .setTitle(title) .setImage(image) .setURL(image) .setFooter(author); await interaction.reply({ embeds: [embed] }); } catch (error) { console.error('Erreur lors de la récupération du meme:', error.message); await interaction.reply("Une erreur s'est produite lors de la récupération du meme."); } } meme(); }, };
3 Replies
d.js toolkit
d.js toolkit5mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Edr0b0t
Edr0b0t5mo ago
And do you know how to fix that there's no typo in the filename it's just the apostrophe at the end
Svitkona
Svitkona5mo ago
inspect the response body you probably need to be auth'd but yeah it's not really a djs thing