【问题标题】:Discord.js How to get description of reddit postDiscord.js 如何获取 reddit 帖子的描述
【发布时间】: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


    【解决方案1】:

    有一个名为reddit-bot 的github 存储库是开源的并且是在线的。你可以从那里提供的代码中得到一个想法。

    https://github.com/lowJ/reddit-bot/blob/master/index.js

    我还发现了这个专门用于获取 memes 的 npm 包,并且还有一个开源 github 存储库。

    https://www.npmjs.com/package/@blad3mak3r/reddit-memes

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-17
      • 1970-01-01
      • 2017-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多