【发布时间】:2021-10-18 18:35:41
【问题描述】:
我有这段代码从 r/memes 顶部获取随机帖子,我希望它显示它选择的随机帖子的标题。
if(msg.content === '-meme')
{
var Channel = msg.channel.name
if(Channel != "chill-bot-log" && Channel != "chill-shitpost") {
msg.channel.send(msg.author + ' ezt a parancsot nem használhatod ebben a csatornában');
console.info(msg.author + " megpróbálta loggolni a botot egy rossz csatornában.");
} else {
loadMemes(message);
}
function loadMemes() {
fetch('https://www.reddit.com/r/memes.json?limit=800&?sort=hot&t=all')
.then(res => res.json())
//.then(res => console.log(res))
.then(json => json.data.children.map(v => v.data.url))
.then(urls => postRandomMeme(urls));
}
function postRandomMeme(urls) {
const randomURL = urls[Math.floor(Math.random() * urls.length) + 1];
const redditUrl = `https://www.reddit.com${randomURL.reddit}`;
const embed = new Discord.RichEmbed({
image: {
url: randomURL
}
});
embed.setFooter('Subreddit : r/memes')
embed.setTitle(redditUrl)
msg.channel.send(embed);
}
}
【问题讨论】:
-
我知道每个人都会告诉我使用randompuppy,但我只想使用我已经拥有的这段代码。
标签: javascript discord.js reddit