Discord Bot2023

YouTube Discord Bot

Discord Bot that automatically tracks YouTube channels for new videos and live streams and pushes notifications to designated channels.

YouTube Discord Bot

Project Overview

An automated Discord bot built with discord.js v14 (ES Modules) and Node.js that monitors subscribed YouTube channels and pushes new video and live stream notifications to designated Discord channels. Supports scheduled crawling (every hour on the hour and half-hour), manual triggers, upcoming stream alerts with user mentions, and full slash command management. MongoDB records pushed history to prevent duplicate notifications.

Technical Challenges & Solutions

YouTube Crawler Reliability

YouTube's page structure is rendered by JavaScript, making simple HTTP crawling unreliable, while heavy Puppeteer usage is slow and resource-intensive.

Solution:
Implemented a dual-crawler strategy: node-fetch + Cheerio for fast primary crawls, with Puppeteer as a fallback for cases where the page requires JS rendering. This keeps performance high while ensuring reliability.

Duplicate Push Prevention

The bot must not re-notify users about content already pushed, even after service restarts.

Solution:
Stored each notified video/stream ID in MongoDB with Mongoose. On every crawl cycle, pushed IDs are queried and compared before sending any Discord messages.

Upcoming Stream Alerts

Users wanted advance notice before a live stream starts, not just a notification when it goes live.

Solution:
Added a scheduled pre-stream check that reads the stream's scheduled start time and sends a tagged mention to subscribed users a configurable interval before the stream begins.

Architecture

系統架構圖

Pure ES Module Node.js architecture using discord.js v14 slash commands. A dual-crawler strategy combines node-fetch + Cheerio (primary fast crawl) with Puppeteer (fallback for JS-rendered pages). PM2 manages the process lifecycle and scheduled restarts. MongoDB (Mongoose ODM) stores push history per channel. Docker is available for containerized deployment.

Learnings

This project deepened my understanding of Discord bot development with the modern slash command API (discord.js v14), web scraping strategies for JavaScript-heavy sites, and reliable scheduled task design. Handling deduplication across restarts and building a maintainable command structure were particularly valuable lessons.

Tech Stack

Core Tech

Node.jsDiscord.js v14JavaScript (ES Modules)

Crawler Tech

node-fetchCheerioPuppeteer

Database

MongoDBMongoose

Deployment Management

PM2Docker