Skip to content

Plugin

DisTube Plugin

new Plugin(): Plugin;

Plugin

readonly aliases?: string[];

Additional identifiers of the source of the plugin, e.g. ["yt"].


distube: DisTube;

DisTube


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.


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

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.

string[]


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.

StreamServer

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.

T

Song<T>

Input song

Awaitable<string>

The search query

override createSearchQuery(song: Song): string {
return `${song.name} ${song.uploader?.name}`;
}

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, …).

void | Promise<void>

Nothing, or a promise that resolves when the plugin is destroyed


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.

Song

Input song

Awaitable<Song<unknown>[]>

The related songs


init(distube): void | Promise<void>;

Initialize the plugin.

It can be asynchronous: use DisTube.create to wait for the initialization of the plugins.

DisTube

The DisTube instance

void | Promise<void>

Nothing, or a promise that resolves when the plugin is initialized

override async init(distube: DisTube) {
this.client = await createSession();
}

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.

T

string

Search query

SearchOptions<T> = {}

Optional options

Promise<SearchResult<T>>

The result of the search

const result = await plugin.search("Never gonna give you up", { limit: 5 });

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.

T

string

Search query

ResolveOptions<T>

Optional options

Awaitable<Song<T> | null>

The song that was found, or null

override async searchSong(query: string): Promise<Song | null> {
return findSong(query);
}