Discord Player
Extractors

Supported Stream Sources

Learn about the supported stream sources in discord-player

By default, discord-player does not support anything (including search operation and streaming). Luckily, discord-player supports the following sources with the help of @discord-player/extractor which comes pre-installed with discord-player:

  • Local file (You must set the search engine to QueryType.FILE in order to play local files, backed by attachment extractor)
  • Raw attachments (backed by attachment extractor)
  • Spotify (backed by spotify extractor)
  • Apple Music (backed by appleMusic extractor)
  • Vimeo (backed by vimeo extractor)
  • Reverbnation (backed by reverbnation extractor)
  • SoundCloud (backed by soundcloud extractor)

If you dont want to stream from certain extractors, you can block them by passing blockStreamFrom: [id, id, ...] to player instantiation options. Disabling streaming from specific extractor completely would be as easy as:

index.js
import { Player } from 'discord-player';
import { Extractor } from 'some-extractor-lib';
 
const player = new Player(client, {
  blockStreamFrom: [
    // now your bot will no longer be able to use
    // this extractor to play audio even if the track was
    // extracted by this extractor
    Extractor.identifier,
  ],
  blockExtractors: [
    // this will block the listed extractors from being
    // able to query metadata (aka search results parsing)
    // This example disables search via this extractor
    Extractor.identifier,
  ],
});

Likewise, You can also force a specific extractor to resolve your search query. This is useful in some cases where you don't want to use other sources.

You can do so by using ext:<EXTRACTOR_IDENTIFIER> in searchEngine value. Example:

index.js
import { SoundCloudExtractor } from '@discord-player/extractor';
 
const result = await player.search(query, {
  // always use soundcloud extractor
  searchEngine: `ext:${SoundCloudExtractor.identifier}`,
});

Overriding bridged stream

Extractors such as AppleMusicExtractor, SpotifyExtractor cannot stream from their original source so they internally use alternative methods to resolve streams. In order to bypass this behavior, you can override createStream function of the extractor like so:

index.js
// The following concept is similar to global `OnBeforeCreateStream` hook, but applies to a particular extractor only
await player.extractors.register(SpotifyExtractor, {
  async createStream(extractor, trackUrl) {
    // extractor refers to SpotifyExtractor instance
    // trackUrl would be a spotify track url
    // return a readable stream or a stream url
    // unlike onBeforeCreateStream, returning nothing here will throw an error
  },
});

Using protocols

Discord Player supports protocol based search queries which can target specific extractor. The query format for this type of action is protocolName:queryValue. For example, if you want to make soundcloud search, you can use scsearch:songName as your search query. Discord Player executes first extractor that supports this query. If none of the extractor support this protocol, discord-player resolves your query via default query resolving algorithm.

List of protocols supported by @discord-player/extractors
ExtractorProtocols
SpotifyExtractorspsearch, spotify
SoundcloudExtractorscsearch, soundcloud
AppleMusicExtractoramsearch, applemusic

Adding more sources

Discord Player provides an Extractor API that enables you to use your custom stream extractor with it. Some packages have been made by the community to add new features using this API.

On this page