【发布时间】:2020-11-08 11:21:10
【问题描述】:
我有这段代码,它从 r/memes 获取随机帖子,并获得带有图片的帖子标题(如果有的话),我得到了很多帮助,我只是想要它能够阅读帖子的描述。如果我想在新闻子版块或其他内容上使用它,我希望能够阅读帖子中的文本。
if (msg.content == '-meme') {
function loadMemes() {
// Fetch JSON
return (
fetch('https://www.reddit.com/r/memes.json?limit=800&?sort=hot&t=all')
.then((res) => res.json())
// Return the actual posts
.then((json) => json.data.children)
);
}
function postRandomMeme(message) {
return loadMemes().then((posts) => {
// Get a random post's title and URL
const { title, url } = posts[Math.floor(Math.random() * posts.length)].data;
// Create the embed
const embed = new Discord.RichEmbed({
title,
image: { url },
footer: { text: 'Subreddit : r/memes' },
});
// Send the embed
return message.channel.send(embed);
});
}
// Usage:
postRandomMeme(msg);
// Log all errors
//.catch(console.error);
}
【问题讨论】:
标签: javascript json discord.js reddit