Discord Player

repository·master·Indexed 20 days ago

https://github.com/androz2091/discord-player

A robust, object-oriented framework for building Discord music bots using JavaScript or TypeScript, built on top of discord-voip. It provides automatic queue management, audio filters, and extensible extractors for services like SoundCloud, Spotify, Apple Music, and Vimeo. The ecosystem includes specialized packages for FFmpeg stream transcoding, Opus encoding/decoding, 15-band PCM equalization via @discord-player/equalizer, and utility classes for LIFO/FIFO queue management.

Tokens
173.5K
Snippets
592
Records
893
Agent score
70%

What's inside discord-player

  1. Overview of Discord VoIP implementation

    master

    The discord-voip package provides the VoIP (Voice over IP) implementation for Discord Player. It is built upon the @discordjs/voice library but includes specific modifications to ensure compatibility and seamless integration with the Discord Player ecosystem.

    Key modifications from the standard @discordjs/voice include:

    • Removal of the VoiceReceiver and its associated components.
    • A modified SecretBox implementation.
  2. Overview of Discord Player classes

    master

    Discord Player provides a comprehensive set of classes for managing Discord bots that interact with the Discord Voice API. Key functional areas include:

    • Audio Playback: AudioPlayer is used to play audio resources (tracks, streams) to voice connections.
    • Queue Management: Classes like GuildQueue, GuildQueuePlayerNode, GuildQueueHistory, and GuildQueueStatistics manage the playback state and history for specific guilds.
    • Audio Processing: AudioFilters, FiltersChain, AFilterGraph, FFmpeg, FFmpegFilterer, and VolumeTransformer handle audio manipulation and effects.
    • Extraction & Searching: BaseExtractor, QueryResolver, SearchResult, and QueryCache facilitate finding and retrieving audio content.
    • Core Framework: Player serves as the main entry point, while Context and PlayerEventsEmitter manage the execution environment and event lifecycle.
  3. Explore Discord Player packages

    master

    The Discord Player monorepo consists of several specialized packages for building Discord music bots and handling audio processing. You can find detailed documentation for each of the following packages:

    • discord-player: The core package for managing music playback and player logic.
    • discord-voip: Handles Discord VoIP functionality.
    • @discord-player/equalizer: Provides audio equalization capabilities.
    • @discord-player/extractor: Contains extractors for retrieving audio from various sources.
    • @discord-player/ffmpeg: Integration with FFmpeg for audio processing.
    • @discord-player/opus: Provides Opus audio encoding/decoding support.
    • @discord-player/utils: A collection of utility functions used across the ecosystem.
  4. Use FFmpeg utilities in Discord Player

    master
    The @discord-player/ffmpeg package provides utilities for managing FFmpeg processes and arguments within Discord Player. It includes the core FFmpeg class for handling FFmpeg operations, various types for configuring FFmpeg sources and options, and utility functions like createFFmpegArgs to transform configuration objects into command-line arguments.
  5. Supported Stream Sources in discord-player

    master

    By default, discord-player does not support streaming or searching. Functionality is provided via the @discord-player/extractor package (pre-installed). Supported sources include:

    • Local files: Requires setting searchEngine to QueryType.FILE (uses attachment extractor).
    • Raw attachments: Uses attachment extractor.
    • Spotify: Uses spotify extractor.
    • Apple Music: Uses appleMusic extractor.
    • Vimeo: Uses vimeo extractor.
    • Reverbnation: Uses reverbnation extractor.
    • SoundCloud: Uses soundcloud extractor.
  6. V7 Breaking Changes Summary

    master

    The following features and behaviors have been removed or changed in v7:

    • VoiceReceiverNode Removed: Voice receiving is no longer supported at the core level. Use @discordjs/voice examples instead.
    • Mediaplex Preinstalled: mediaplex is now included by default as a drop-in replacement for @discordjs/opus. You no longer need to install @discordjs/opus or opusscript separately.
    • YoutubeExtractor Removed: YouTube playback and metadata extraction are discontinued. The library still provides query detection for YouTube links but does not support playback.
    • lyricsExtractor Removed: Replaced by a new, more flexible lyrics API that supports synced lyrics.
    • IP Rotator Removed: The built-in IP rotator is removed to keep the library lightweight; extractors should implement their own if necessary.
    • tweetnacl Support Removed: No longer supported due to Discord's voice encryption requirements.
  7. Configure FFmpeg options and sources

    master

    When working with FFmpeg, use these types to manage streams and configurations:

    • FFmpegOptions: General configuration for FFmpeg.
    • FFmpegSource: Defines the source of the FFmpeg stream.
    • FFmpegStreamOptions: Specific options for FFmpeg streams.
    • ResolvedFFmpegSource: A source that has been successfully resolved.
    • FFmpegLib: Reference to the FFmpeg library instance.
    • FFmpegReport: Data regarding FFmpeg execution/status.
  8. Implement a custom extractor using BaseExtractor

    master

    The BaseExtractor class is the foundation for creating custom music extractors in discord-player. When implementing a new extractor, you will typically extend this class and override key methods to handle queries, stream tracks, and manage the extractor lifecycle.

    Core Lifecycle Methods

    • activate(): Executed when the extractor is activated.
    • deactivate(): Executed when the extractor is deactivated.
    • reconfigure(options): Updates the extractor with new initialization options.

    Key Functionality Methods

    • handle(query, context): The primary entry point for processing a search query. It should return an ExtractorInfo object.
    • stream(info): Responsible for returning an ExtractorStreamable for a given track.
    • validate(query, type?): Checks if a given query is valid for this extractor.
    • getRelatedTracks(track, history): Retrieves related tracks based on a source track and history.
    // Example of how you might instantiate or extend the base class
    new BaseExtractor(context, options);
  9. Core Classes in discord-voip

    master

    The discord-voip library provides several key classes for managing audio playback in Discord voice channels:

    • AudioPlayer: Used to play audio resources (e.g., tracks, streams) to voice connections.
    • AudioResource: Represents an audio resource that can be played by an AudioPlayer.
    • VoiceConnection: A connection to the voice server of a Guild, used to play audio in voice channels.
    • PlayerSubscription: Represents a subscription of a VoiceConnection to an AudioPlayer, enabling the player to output audio to that specific connection.
    • AudioPlayerError: An error emitted by an AudioPlayer, containing an attached resource to assist with debugging.