npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

discord-stream-selfbot-yt

v1.0.0

Published

Discord selfbot video streaming with YouTube URL support (for educational purposes)

Downloads

91

Readme

Discord Stream Selfbot with YouTube Support

Enhanced version of Discord-video-stream with YouTube URL support

[!CAUTION] Using any kind of automation programs on your account can result in your account getting permanently banned by Discord. Use at your own risk. This package is for educational purposes only.

This project extends the Discord-video-stream library with YouTube URL support, making it easy to stream YouTube videos directly to Discord voice channels.

✨ Features

  • 🎥 Play video & audio in Discord voice channels (Go Live or webcam video)
  • 🎬 YouTube URL Support - Stream YouTube videos directly using their URLs
  • 🔄 Auto-Retry - Automatic retry on YouTube extraction failures (configurable, default 3 attempts)
  • 🛡️ Robust Error Handling - Comprehensive error messages and fallback mechanisms
  • 🔧 Supports H.264, H.265, and VP8 video codecs
  • ⚙️ Customizable video quality, bitrate, and encoding settings
  • 📺 Both direct video URLs and YouTube URLs supported
  • 🎯 Advanced Example - Ultra-advanced single-file bot with queue system, status monitoring, and more

📋 Requirements

For full functionality, this library requires an FFmpeg build with libzmq enabled:

📦 Installation

Install the package alongside its peer-dependency discord.js-selfbot-v13:

npm install discord-stream-selfbot-yt
npm install discord.js-selfbot-v13

🚀 Usage

Basic Setup

import { Client } from "discord.js-selfbot-v13";
import { Streamer } from 'discord-stream-selfbot-yt';

const streamer = new Streamer(new Client());
await streamer.client.login('YOUR_TOKEN_HERE');

Join a Voice Channel

await streamer.joinVoice("GUILD_ID", "CHANNEL_ID");

Stream YouTube Videos with Advanced Options

import { prepareStream, playStream, Utils } from "discord-stream-selfbot-yt";

try {
    // Works with YouTube URLs!
    const youtubeUrl = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
    
    const { command, output } = await prepareStream(youtubeUrl, {
        height: 1080,
        frameRate: 30,
        bitrateVideo: 5000,
        bitrateVideoMax: 7500,
        videoCodec: Utils.normalizeVideoCodec("H264"),
        h26xPreset: "veryfast",
        verbose: true, // Enable detailed logging
        
        // YouTube-specific options
        youtubeOptions: {
            maxRetries: 3,      // Retry failed extractions (default: 3)
            retryDelay: 2000,   // Delay between retries in ms (default: 1000)
            quality: 'highest', // Video quality (highest, lowest, etc.)
            preferFormat: 'any' // Format preference (any, mp4, webm)
        }
    });
    
    command.on("error", (err, stdout, stderr) => {
        console.error("FFmpeg error:", err);
    });

    await playStream(output, streamer, {
        type: "go-live" // or "camera"
    });

    console.log("Finished playing video");
} catch (e) {
    console.error(e);
}

Stream Direct Video URLs

The package also supports direct video URLs (like the original library):

const directUrl = "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4";

const { command, output } = await prepareStream(directUrl, {
    height: 1080,
    frameRate: 30,
    bitrateVideo: 5000,
    bitrateVideoMax: 7500,
    videoCodec: Utils.normalizeVideoCodec("H264")
});

await playStream(output, streamer, { type: "go-live" });

⚙️ Configuration Options

Enhanced Prepare Stream Options

{
    // Standard encoding options
    width?: number;              // Video output width
    height?: number;             // Video output height
    frameRate?: number;          // Video output FPS
    bitrateVideo?: number;       // Video average bitrate (kbps)
    bitrateVideoMax?: number;    // Video max bitrate (kbps)
    bitrateAudio?: number;       // Audio bitrate (kbps)
    includeAudio?: boolean;      // Enable audio output
    hardwareAcceleratedDecoding?: boolean;  // Use hardware acceleration
    videoCodec?: SupportedVideoCodec;  // H264, H265, or VP8
    h26xPreset?: string;         // Encoding preset (ultrafast, veryfast, etc.)
    minimizeLatency?: boolean;   // Minimize latency
    customHeaders?: Record<string, string>;  // Custom HTTP headers
    customFfmpegFlags?: string[];  // Custom FFmpeg flags
    
    // Enhanced options
    verbose?: boolean;           // Enable detailed logging
    
    // YouTube-specific options
    youtubeOptions?: {
        maxRetries?: number;     // Max retry attempts (default: 3)
        retryDelay?: number;     // Delay between retries in ms (default: 1000)
        quality?: 'highest' | 'lowest' | 'highestaudio' | 'lowestaudio' | 'highestvideo' | 'lowestvideo';
        preferFormat?: 'any' | 'mp4' | 'webm';  // Preferred format
    }
}

YouTube Options Details

The youtubeOptions provides robust YouTube extraction:

  • maxRetries: Number of retry attempts if extraction fails (default: 3)
  • retryDelay: Milliseconds to wait between retries (default: 1000)
  • quality: Preferred quality level for the stream
  • preferFormat: Container format preference (mp4, webm, or any)

Play Stream Options

{
    type?: "go-live" | "camera";  // Stream type
    width?: number;               // Override video width
    height?: number;              // Override video height
    frameRate?: number;           // Override frame rate
    readrateInitialBurst?: number;  // FFmpeg readrate_initial_burst
}

📝 Example Bot Commands

// In your Discord bot message handler:

if (msg.content.startsWith("$play-live")) {
    const url = msg.content.split(" ")[1];
    
    // Supports both YouTube URLs and direct video URLs!
    const { command, output } = await prepareStream(url, {
        height: 1080,
        frameRate: 30,
        bitrateVideo: 5000,
        videoCodec: Utils.normalizeVideoCodec("H264")
    });
    
    await playStream(output, streamer, { type: "go-live" });
}

Example Commands:

$play-live https://www.youtube.com/watch?v=dQw4w9WgXcQ
$play-live http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4
$play-cam https://www.youtube.com/watch?v=jNQXAC9IVRw

🔍 YouTube Detection

The package automatically detects YouTube URLs and extracts the best quality stream:

import { isYouTubeUrl, getYouTubeStreamUrl } from "discord-stream-selfbot-yt";

if (isYouTubeUrl(url)) {
    const streamInfo = await getYouTubeStreamUrl(url);
    console.log("Title:", streamInfo.title);
    console.log("Duration:", streamInfo.duration, "seconds");
}

🎯 Running the Examples

Basic Example

  1. Navigate to examples/youtube-example
  2. Configure src/config.json:
{
    "token": "YOUR_SELF_TOKEN",
    "acceptedAuthors": ["YOUR_USER_ID"]
}
  1. Install dependencies: npm install
  2. Build: npm run build
  3. Start: npm run start
  4. Join a voice channel and use commands like:
    • $play-live <YouTube URL or direct video URL>
    • $play-cam <YouTube URL or direct video URL>
    • $disconnect

Ultra Advanced Example 🔥

For a production-ready bot with advanced features, check out examples/ultra-advanced-bot.ts!

Features:

  • Queue System - Add multiple videos to queue
  • Auto-Retry - Automatic retry on YouTube extraction failures
  • Status Monitoring - Real-time stream status and statistics
  • Error Recovery - Comprehensive error handling and recovery
  • Rich Commands - Full command system ($play, $queue, $skip, $status, etc.)
  • Detailed Logging - Verbose logging with timestamps and status
  • Graceful Shutdown - Proper cleanup on exit

Commands Available:

$play <url>         - Play video in current voice channel
$play-live <url>    - Play as Go Live stream
$play-cam <url>     - Play as camera stream
$queue <url>        - Add video to queue
$skip               - Skip current video
$stop               - Stop playback and clear queue
$queue-list         - Show current queue
$queue-clear        - Clear the queue
$disconnect         - Leave voice channel
$status             - Show stream status
$help               - Show help message

Quick Start:

# Copy the ultra-advanced example
cp examples/ultra-advanced-bot.ts my-bot.ts

# Edit configuration at the top of the file
# Set your token and user IDs

# Install dependencies
npm install

# Run directly with ts-node or compile first
npx ts-node my-bot.ts
# OR
npx tsc my-bot.ts && node my-bot.js

⚠️ Important Notes

  • Self-bot tokens only: Discord blocks video streaming from bot tokens
  • Educational purposes: This is for learning and experimentation
  • Account risk: Using self-bots violates Discord's ToS and can result in account termination
  • Protocol changes: Discord may change their protocol at any time, breaking functionality

📚 API Reference

Main Functions

  • prepareStream(url, options, signal?) - Prepare a stream from YouTube URL or direct video URL
  • playStream(output, streamer, options?, signal?) - Play the prepared stream
  • isYouTubeUrl(url) - Check if a URL is a YouTube URL
  • getYouTubeStreamUrl(url) - Extract direct stream URL from YouTube
  • processUrl(url) - Process any URL (YouTube or direct)

Classes

  • Streamer(client) - Main streaming class
  • Utils.normalizeVideoCodec(codec) - Normalize video codec names

🙏 Credits

Based on Discord-video-stream by dank074 and contributors.

Enhanced with YouTube support for educational purposes.

📄 License

ISC

⚖️ Disclaimer

This software is provided for educational purposes only. The authors are not responsible for any misuse or damage caused by this software. Use at your own risk and ensure compliance with Discord's Terms of Service and applicable laws.