【问题标题】:How would you go about where a user types in {prefix}reddit {subreddit} (then replies a random image from that subreddit)您将如何处理用户在 {prefix}reddit {subreddit} 中输入的位置(然后从该 subreddit 回复随机图像)
【发布时间】:2019-10-16 10:31:20
【问题描述】:

到目前为止,我得到了这个使用随机小狗从设置的 subreddits 中提取图像的方法。 我会将 meme 更改为 cmd 的 reddit。另外,如果频道未标记为 NSFW,您将如何限制人们从 18 岁以上的 subreddit 中提取图像

const randomPuppy = require('random-puppy');

exports.run = async (client, message, args) => {

  let reddit = [
    "meme",
    "animemes",
    "MemesOfAnime",
    "animememes",
    "AnimeFunny",
    "dankmemes",
    "dankmeme",
    "wholesomememes",
    "MemeEconomy",
    "techsupportanimals",
    "meirl",
    "me_irl",
    "2meirl4meirl",
    "AdviceAnimals"
  ]

  let subreddit = reddit[Math.floor(Math.random() * reddit.length)];

  message.channel.startTyping();

  randomPuppy(subreddit).then(async url => {
    await message.channel.send({
      files: [{
        attachment: url,
        name: 'meme.png'
      }]
    }).then(() => message.channel.stopTyping());
  }).catch(err => console.error(err));

};
exports.help = {
    name: 'meme',
    aliases: [],
    description: 'What can I say ͡°-͜ʖ-͡°',
    usage: 'meme'
};

【问题讨论】:

  • 我不明白你的问题,你能澄清一下吗?你想要什么?阻止机器人拉随机 nsfw?阻止它从 nsfw reddit 中拉出?

标签: javascript node.js discord discord.js


【解决方案1】:

您可以简单地使用用户提供的参数,而不是定义一组 subreddits 并选择一个随机的。

const randomPuppy = require('random-puppy');

exports.run = async (client, message, args) => {
  // Assuming args[1] is the name of the subreddit.
  try {
    if (!args[1]) {
      // Insert your code for choosing from a random subreddit.
    } else {
      if (args[2]) return await message.channel.send('Too many arguments.');

      const imgURL = await randomPuppy(args[1]);

      await message.channel.send({
        files: [{
          attachment: imgURL,
          name: 'image.png'
        }];
      });
    }
  } catch(err) {
    console.error(err);
  }
};

exports.help = {
  name: 'reddit',
  aliases: [],
  description: 'Retrieve a random picture from a subreddit',
  usage: 'meme'
};

至于 NSFW 内容的限制,您可能必须使用某种裸露/NSFW 检测系统扫描图像。要检查频道是否标记为 NSFW,您可以使用...

if (message.channel.nsfw === false) console.log('Not an NSFW channel'); 

【讨论】:

  • 谢谢?我现在明白这个功能了
  • 我相信使用 reddit JSON API (reddit.com/r/memes.json) 可以获取关于它是否被标记为 NSFW 的数据,然后像 if (!message.channel.nsfw && post.nsfw) return 'blah' 一样进行检查
猜你喜欢
  • 1970-01-01
  • 2019-03-11
  • 1970-01-01
  • 2018-09-27
  • 1970-01-01
  • 2015-09-15
  • 2019-10-09
  • 2018-03-20
  • 1970-01-01
相关资源
最近更新 更多