- requires
npm install rss-parser - youtube channel id is prefilled
- variable n in
modules.jsis the number of messages to check to tell if the video has been posted already, - guildname and channel name are Not prefilled
Last active
February 21, 2019 01:59
-
-
Save binyamin/221bff976a1136adfad0d1eeeee65aea to your computer and use it in GitHub Desktop.
Youtube Video Checker Bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const Discord = require('discord.js'); | |
| ... | |
| const rss = require('./module.js'); | |
| // Check for new youtube videos from a channel | |
| client.setInterval(() => { | |
| let guild = client.guilds.find(g => g.id === <guild_id>); //Or, let guild = client.guilds.find(g => g.name === <guild_name>); | |
| let channel = guild.channels.find(ch => ch.name === <channel_name>); | |
| rss.updateFeed(channel); | |
| }, 180000); | |
| ... | |
| client.login(token); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { RichEmbed } = require('discord.js'); | |
| const Parser = require('rss-parser'); | |
| let n = 3; | |
| module.exports = { | |
| updateFeed(channel) { | |
| let rssParser = new Parser(); | |
| rssParser.parseURL('https://www.youtube.com/feeds/videos.xml?channel_id=UCVyRiMvfUNMA1UPlDPzG5Ow') | |
| .then(feed => { | |
| let last = feed.items[0]; | |
| const embed = new RichEmbed() | |
| .setTitle(last.title) | |
| .setAuthor(last.author) | |
| .setURL(last.link) | |
| .setImage(`https://img.youtube.com/vi/${last.id.replace('yt:video:', '')}/0.jpg`) | |
| .setColor(0x00ad7d) | |
| .setTimestamp(new Date(last.isoDate)); | |
| channel.fetchMessages({limit: n}) | |
| .then(msg => { | |
| var msgArray = msg.array(); | |
| var id = ''; | |
| for (var i = 0; i < n; i++) { | |
| if(msgArray[i].embeds[0]) { | |
| id = msgArray[i].embeds[0].url.replace('https://www.youtube.com/watch?v=', ''); | |
| } | |
| } | |
| if(id !== last.id.replace('yt:video:', '')) { | |
| channel.send(embed); | |
| } | |
| }) | |
| .catch(console.error) | |
| }) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment