Discord Player
Creating a music bot

Extractors Integration

Learn how to integrate extractors in Discord Player

Discord Player on itself does not provide a way to resolve the query to a track. It requires you to provide extractors (or plugins) to resolve your input to a track. Extractors are the plugins that provide the ability to resolve the query to a track. Extractors may or may not support audio extraction though.

Design Planning

Before we dive into the code, let's plan the design of our extractors integration:

  1. Extractor Installation: We will install the @discord-player/extractor package.
  2. Extractor Loading: We will load the default extractors provided by the package.
  3. Custom Extractors: We will mention the possibility of using community-built extractors.

Official Extractors

Discord Player provides a set of default extractors that you can use. These extractors are provided by the @discord-player/extractor package. You can install it by running:

npm install @discord-player/extractor

You may also choose to not use the default extractors and find other extractors that suit your needs. The official extractor package provides the following extractors:

ExtractorDescriptionSupports StreamingSupports Search
AttachmentExtractorResolves raw url or local files to playable TrackYesNo
SoundCloudExtractorResolves SoundCloud url, playlist or album to playable Track. Copyrighted tracks cannot be played.YesYes
VimeoExtractorResolves Vimeo url to playable Track.YesNo
AppleMusicExtractorResolves Apple Music url, album or playlist to playable Track.NoYes
SpotifyExtractorResolves Spotify url, album or playlist to playable Track.NoYes
ReverbnationExtractorResolves Reverbnation url to playable Track.YesNo

The extractors that do not support streaming can only be used for search. They cannot be used to play the audio. In other words, extractors such as AppleMusicExtractor and SpotifyExtractor can only be used to search for tracks, but not to play them.

If the query is resolved via extractors that do not support streaming, Discord Player uses alternative streaming method called bridging to facilitate the playback. This method may not be as efficient and accurate.

Bridging is a method where track extracted by one extractor is passed to another extractor that supports streaming. If the track is unable to be bridged, Discord Player will skip the track and move to the next track in the queue.

Community Extractors

You can also find community built extractors that provide additional functionality. These extractors may not be officially supported by Discord Player. You can find community extractors on Community showcase list.

Some extractors may violate the terms of service of the platform they are extracting from. Make sure to read the terms of service of the platform before using the extractors. Discord Player is not responsible for any violation of terms of service, as it gives you full control over the extractors.

Loading @discord-player/extractor

To load the default extractors, you can use the following code:

import { DefaultExtractors } from '@discord-player/extractor';
 
await player.extractors.loadMulti(DefaultExtractors);

DefaultExtractors is an array of extractors that @discord-player/extractor provides. You can also load a single extractor by using player.extractors.register method.

It is up to you to decide which extractors you want to use. Having too many extractors may slow down the query resolution process.

On this page