showing results for - "meme discord js"
Cameron
02 May 2017
1const https = require('https');
2const Discord = require('discord.js');
3const url = 'https://www.reddit.com/r/meme/hot/.json?limit=100'
4
5module.exports = {
6    name: 'meme',
7    description: 'sends meme',
8    execute(cleint, message, args) {
9
10        https.get(url, (result) => {
11            var body = ''
12            result.on('data', (chunk) => {
13                body += chunk
14            })
15
16            result.on('end', () => {
17                var response = JSON.parse(body)
18                var index = response.data.children[Math.floor(Math.random() * 99) + 1].data
19
20                if (index.post_hint !== 'image') {
21
22                    var text = index.selftext
23                    const textembed = new Discord.MessageEmbed()
24                        .setTitle(subRedditName)
25                        .setColor(9384170)
26                        .setDescription(`[${title}](${link})\n\n${text}`)
27                        .setURL(`https://reddit.com/${subRedditName}`)
28
29                    message.channel.send(textembed)
30                }
31
32                var image = index.preview.images[0].source.url.replace('&', '&')
33                var title = index.title
34                var link = 'https://reddit.com' + index.permalink
35                var subRedditName = index.subreddit_name_prefixed
36
37                if (index.post_hint !== 'image') {
38                    const textembed = new Discord.RichEmbed()
39                        .setTitle(subRedditName)
40                        .setColor(9384170)
41                        .setDescription(`[${title}](${link})\n\n${text}`)
42                        .setURL(`https://reddit.com/${subRedditName}`)
43
44                    message.channel.send(textembed)
45                }
46                console.log(image);
47                const imageembed = new Discord.MessageEmbed()
48                    .setTitle(subRedditName)
49                    .setImage(image)
50                    .setColor(9384170)
51                    .setDescription(`[${title}](${link})`)
52                    .setURL(`https://reddit.com/${subRedditName}`)
53                message.channel.send(imageembed)
54            }).on('error', function (e) {
55                console.log('Got an error: ', e)
56            })
57        })
58    },
59}