also show text and not only image, and show the proper subreddit if using thing like random

This commit is contained in:
Loïc Bersier 2019-06-16 19:15:52 +02:00
parent dacc6e4e1f
commit 476d971e40

View file

@ -23,8 +23,8 @@ class RedditCommand extends Command {
} }
async exec(message, args) { async exec(message, args) {
let i = 0; //let i = 0;
let a = 0; //let a = 0;
if (!args.sub) if (!args.sub)
return; return;
@ -33,20 +33,17 @@ class RedditCommand extends Command {
}).then((response) => { }).then((response) => {
if (!response.data) if (!response.data)
return message.channel.send('Not a valid subreddit'); return message.channel.send('Not a valid subreddit');
while (response.data.children[i].data.post_hint !== 'image') {
i = Math.floor((Math.random() * response.data.children.length)); let i = Math.floor((Math.random() * response.data.children.length));
a++;
if (a == 5)
return message.channel.send('Could not find any images');
}
if (response.data.children[i].data.over_18 == true && !message.channel.nsfw) if (response.data.children[i].data.over_18 == true && !message.channel.nsfw)
return message.channel.send('No nsfw'); return message.channel.send('No nsfw');
const redditEmbed = new MessageEmbed() const redditEmbed = new MessageEmbed()
.setColor('#ff9900') .setColor('#ff9900')
.setTitle(response.data.children[i].data.title) .setTitle(response.data.children[i].data.title)
.setImage(response.data.children[i].data.url) .setImage(response.data.children[i].data.url)
.setDescription(response.data.children[i].data.selftext)
.setURL('https://reddit.com' + response.data.children[i].data.permalink) .setURL('https://reddit.com' + response.data.children[i].data.permalink)
.setFooter(`/r/${args.sub} | ⬆ ${response.data.children[i].data.ups}${response.data.children[i].data.num_comments}`); .setFooter(`/r/${response.data.children[i].data.subreddit} | ⬆ ${response.data.children[i].data.ups}${response.data.children[i].data.num_comments}`);
message.channel.send(redditEmbed); message.channel.send(redditEmbed);
}); });