Plugin
DisTube Plugin
Extended by
Section titled “Extended by”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new Plugin(): Plugin;Returns
Section titled “Returns”Plugin
Properties
Section titled “Properties”aliases?
Section titled “aliases?”readonly aliases?: string[];Additional identifiers of the source of the plugin, e.g. ["yt"].
distube
Section titled “distube”distube: DisTube;DisTube
playable?
Section titled “playable?”readonly playable?: boolean;Whether the songs of this plugin can be played directly.
When it is false, the songs of the plugin are resolved to a playable
version by another plugin. It defaults to true.
source?
Section titled “source?”readonly source?: string;The identifier of the source of the plugin.
It defaults to the name of the class, lowercased, without the Plugin
suffix (MyPlugin -> myplugin).
It is used to route a search to a plugin, and to find a plugin with DisTube#getPlugin.
abstract readonly type: PluginType;Type of the plugin
Accessors
Section titled “Accessors”identifiers
Section titled “identifiers”Get Signature
Section titled “Get Signature”get identifiers(): string[];Every identifier of this plugin: its Plugin.source and its Plugin.aliases, lowercased.
The static properties of the class are used when the instance ones are not defined, so a plugin can declare them either way.
Returns
Section titled “Returns”string[]
streams
Section titled “streams”Get Signature
Section titled “Get Signature”get streams(): StreamServer;The local HTTP server of the DisTube instance.
Register a handler on it when the plugin cannot hand out a static URL to FFmpeg, instead of running its own server.
Returns
Section titled “Returns”Methods
Section titled “Methods”createSearchQuery()
Section titled “createSearchQuery()”createSearchQuery<T>(song): Awaitable<string>;Create the query used to find a playable version of a song.
It is used when the plugin cannot play the songs it resolves.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”Song<T>
Input song
Returns
Section titled “Returns”Awaitable<string>
The search query
Example
Section titled “Example”override createSearchQuery(song: Song): string { return `${song.name} ${song.uploader?.name}`;}destroy()
Section titled “destroy()”destroy(): void | Promise<void>;Destroy the plugin.
It is called when the DisTube instance is destroyed. Override it to release every resource held by the plugin (HTTP servers, timers, browser sessions, …).
Returns
Section titled “Returns”void | Promise<void>
Nothing, or a promise that resolves when the plugin is destroyed
getRelatedSongs()
Section titled “getRelatedSongs()”getRelatedSongs(_song): Awaitable<Song<unknown>[]>;Get related songs from a supported url.
Override it to enable the autoplay for your source. Return an empty array when your source does not have any related songs.
Parameters
Section titled “Parameters”Input song
Returns
Section titled “Returns”The related songs
init()
Section titled “init()”init(distube): void | Promise<void>;Initialize the plugin.
It can be asynchronous: use DisTube.create to wait for the initialization of the plugins.
Parameters
Section titled “Parameters”distube
Section titled “distube”The DisTube instance
Returns
Section titled “Returns”void | Promise<void>
Nothing, or a promise that resolves when the plugin is initialized
Example
Section titled “Example”override async init(distube: DisTube) { this.client = await createSession();}search()
Section titled “search()”search<T>(query, options?): Promise<SearchResult<T>>;Search for the songs of the source.
The default implementation returns the single result of Plugin#searchSong. Override it to return more results, or to return a playlist.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”string
Search query
options?
Section titled “options?”SearchOptions<T> = {}
Optional options
Returns
Section titled “Returns”Promise<SearchResult<T>>
The result of the search
Example
Section titled “Example”const result = await plugin.search("Never gonna give you up", { limit: 5 });searchSong()
Section titled “searchSong()”searchSong<T>(_query, _options): Awaitable<Song<T> | null>;Search for a song of the source.
Override it to enable the search of your source. It returns null by
default, because a source that cannot be searched does not have any result.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”_query
Section titled “_query”string
Search query
_options
Section titled “_options”Optional options
Returns
Section titled “Returns”The song that was found, or null
Example
Section titled “Example”override async searchSong(query: string): Promise<Song | null> { return findSong(query);}