到目前为止,我已经知道可以使用random-puppy从设置的subreddits中提取图像。 我将把模因更改为reddit for cmd。加上如果频道未标记为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'
};
答案 0 :(得分:0)
您可以简单地使用用户提供的参数来代替定义子查询数组并选择一个随机子数组。
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');