├── .gitignore ├── LICENSE ├── config.js ├── index.js ├── package.json └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | json.sqlite 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 INEX07 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | token: "YOUR_DISCORD_BOT_TOKEN", 3 | channel: "XXXXXXXXXXXXXXXXXX", 4 | messageTemplate: "Hello @everyone, **{author}** just now uploaded a video **{title}**!\n{url}", 5 | channel_id: "YOUTUBE_CHANNEL_ID", 6 | watchInterval: 30000 7 | } -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const Discord = require("discord.js"); 2 | const client = new Discord.Client(); 3 | client.db = require("quick.db"); 4 | client.request = new (require("rss-parser"))(); 5 | client.config = require("./config.js"); 6 | 7 | client.on("ready", () => { 8 | console.log("I'm ready!"); 9 | handleUploads(); 10 | }); 11 | 12 | function handleUploads() { 13 | if (client.db.fetch(`postedVideos`) === null) client.db.set(`postedVideos`, []); 14 | setInterval(() => { 15 | client.request.parseURL(`https://www.youtube.com/feeds/videos.xml?channel_id=${client.config.channel_id}`) 16 | .then(data => { 17 | if (client.db.fetch(`postedVideos`).includes(data.items[0].link)) return; 18 | else { 19 | client.db.set(`videoData`, data.items[0]); 20 | client.db.push("postedVideos", data.items[0].link); 21 | let parsed = client.db.fetch(`videoData`); 22 | let channel = client.channels.cache.get(client.config.channel); 23 | if (!channel) return; 24 | let message = client.config.messageTemplate 25 | .replace(/{author}/g, parsed.author) 26 | .replace(/{title}/g, Discord.Util.escapeMarkdown(parsed.title)) 27 | .replace(/{url}/g, parsed.link); 28 | channel.send(message); 29 | } 30 | }); 31 | }, client.config.watchInterval); 32 | } 33 | 34 | client.login(client.config.token); 35 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "youtube-notification-bot", 3 | "version": "1.0.0", 4 | "description": "Simple and easy to use discord bot to notify members whenever a video is posted on a YouTube channel.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "node index.js" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/Snowflake107/youtube-notification-bot.git" 12 | }, 13 | "keywords": [ 14 | "youtube", 15 | "discord.js", 16 | "notification-bot" 17 | ], 18 | "author": "Snowflake07", 19 | "license": "MIT", 20 | "bugs": { 21 | "url": "https://github.com/Snowflake07/youtube-notification-bot/issues" 22 | }, 23 | "homepage": "https://github.com/Snowflake07/youtube-notification-bot#readme", 24 | "dependencies": { 25 | "discord.js": "^12.0.2", 26 | "quick.db": "^7.0.0-b22", 27 | "rss-parser": "^3.7.5" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Youtube Notification Bot 2 | Simple and easy to use discord bot to notify members whenever a video is posted on a YouTube channel. 3 | 4 | # Packages Used 5 | - **[discord.js](https://npmjs.com/package/discord.js "View on npmjs")** 6 | - **[quick.db](https://npmjs.com/package/quick.db "View on npmjs")** 7 | - **[rss-parser](https://npmjs.com/package/rss-parser "View on npmjs")** 8 | 9 | # config.js 10 | 11 | ```js 12 | module.exports = { 13 | token: "YOUR_DISCORD_BOT_TOKEN", // discord bot token 14 | channel: "DISCORD_CHANNEL_ID", // channel id of a channel to send message 15 | messageTemplate: "Hello @everyone, **{author}** just now uploaded a video **{title}**!\n{url}", // message to send on discord 16 | channel_id: "YOUTUBE_CHANNEL_ID", // youtube channel id 17 | watchInterval: 30000 // Check every 30 seconds 18 | }; 19 | ``` 20 | --------------------------------------------------------------------------------