Skip to content

DisTube

DisTube class

new DisTube(client, opts?): DisTube;

Create a new DisTube class.

Client

Discord.JS client

DisTubeOptions = {}

Custom DisTube options

DisTube

DisTubeError

const distube = new DisTube(client, { nsfw: false });

TypedEmitter<TypedDisTubeEvents>.constructor

readonly client: Client;

Discord.js v14 client


readonly filters: Filters;

DisTube ffmpeg audio filters


readonly handler: DisTubeHandler;

DisTube internal handler


readonly options: Options;

DisTube options


readonly plugins: DisTubePlugin[];

DisTube plugins


readonly queues: QueueManager;

Queues manager


readonly streams: StreamServer;

The local HTTP server the plugins use to stream the audio.

A plugin that cannot hand out a static URL to FFmpeg registers a handler on it, instead of running its own server.


readonly voices: DisTubeVoiceManager;

DisTube voice connections manager


static defaultMaxListeners: number;

TypedEmitter.defaultMaxListeners

get version(): string;

DisTube version

string


get static version(): string;

DisTube version

string

addListener<U>(event, listener): this;

U extends keyof DisTubeEvents

U

TypedDisTubeEvents[U]

this

TypedEmitter.addListener


createCustomPlaylist(songs, options?): Promise<Playlist<unknown>>;

Create a custom playlist

(string | Song<unknown>)[]

Array of url or Song

CustomPlaylistOptions = {}

Optional options

Promise<Playlist<unknown>>

The created playlist

DisTubeError When the array is empty, or when it does not have any valid song


debug(message): void;

Emit debug event

string

debug message

void

Nothing


destroy(): Promise<void>;

Destroy the DisTube instance.

Stops every queue, leaves every voice channel, destroys every plugin and removes every listener. Call it before your Discord.js client is destroyed to release all resources.

Promise<void>

A promise that resolves when every resource is released

await distube.destroy();

emit<U>(event, ...args): boolean;

Emit an event of the DisTube instance.

The special Events.ERROR event is handled differently than the other events: Node.js throws an ERR_UNHANDLED_ERROR when the special "error" event is emitted without any listener, which crashes the whole process.

Instead of crashing, DisTube follows DisTubeOptions.unhandledError ("log" by default).

U extends keyof DisTubeEvents

U

The event name

…Parameters<TypedDisTubeEvents[U]>

The event arguments

boolean

true when the event had listeners, false otherwise

TypedEmitter.emit


emitError(
error,
queue,
song?
): void;

/** /** /**

  • Emit error event

Error

error *

Queue

The queue encountered the error *

Song<unknown>

The playing song when encountered the error *

void

Nothing


eventNames<U>(): U[];

U extends keyof DisTubeEvents

U[]

TypedEmitter.eventNames


getMaxListeners(): number;

number

TypedEmitter.getMaxListeners


getPlugin(source):
| DisTubePlugin
| undefined;

Get a plugin by the identifier of its source.

It matches the Plugin.source of the plugin, or one of its Plugin.aliases. The identifier of the class is used when the plugin does not define a source (MyPlugin -> myplugin).

string

The identifier of the source

| DisTubePlugin | undefined

The plugin, or undefined when there is none

const plugin = distube.getPlugin("myplugin");

getQueue(guild): Queue | undefined;

Get the guild queue

GuildIdResolvable

The type can be resolved to give a Queue

Queue | undefined

The queue of the guild, or undefined when there is none

const queue = distube.getQueue(guildId);

listenerCount(type): number;

keyof DisTubeEvents

number

TypedEmitter.listenerCount


listeners<U>(type): TypedDisTubeEvents[U][];

U extends keyof DisTubeEvents

U

TypedDisTubeEvents[U][]

TypedEmitter.listeners


off<U>(event, listener): this;

U extends keyof DisTubeEvents

U

TypedDisTubeEvents[U]

this

TypedEmitter.off


on<U>(event, listener): this;

U extends keyof DisTubeEvents

U

TypedDisTubeEvents[U]

this

TypedEmitter.on


once<U>(event, listener): this;

U extends keyof DisTubeEvents

U

TypedDisTubeEvents[U]

this

TypedEmitter.once


play<T>(
voiceChannel,
song,
options?
): Promise<void>;

Play / add a song or playlist from url. Search and play a song (with ExtractorPlugin) if it is not a valid url.

T = unknown

VoiceBasedChannel

The channel will be joined if the bot isn’t in any channels, the bot will be moved to this channel if DisTubeOptions.joinNewVoiceChannel is true

| string | Song<unknown> | Playlist<unknown>

URL | Search string | Song | Playlist

PlayOptions<T> = {}

Optional options

Promise<void>

A promise that resolves when the song is added to the queue

DisTubeError

await distube.play(channel, "Never gonna give you up", { message });

prependListener<U>(event, listener): this;

U extends keyof DisTubeEvents

U

TypedDisTubeEvents[U]

this

TypedEmitter.prependListener


prependOnceListener<U>(event, listener): this;

U extends keyof DisTubeEvents

U

TypedDisTubeEvents[U]

this

TypedEmitter.prependOnceListener


rawListeners<U>(type): TypedDisTubeEvents[U][];

U extends keyof DisTubeEvents

U

TypedDisTubeEvents[U][]

TypedEmitter.rawListeners


removeAllListeners(event?): this;

keyof DisTubeEvents

this

TypedEmitter.removeAllListeners


removeListener<U>(event, listener): this;

U extends keyof DisTubeEvents

U

TypedDisTubeEvents[U]

this

TypedEmitter.removeListener


search<T>(query, options?): Promise<SearchResult<T>>;

Search for the songs of the plugins.

The plugins are used in the order they were registered. When ResolveOptions.source is given, only the matching plugin is used.

T = unknown

string

The search query

SearchOptions<T> = {}

Optional options

Promise<SearchResult<T>>

The result of the search

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

setMaxListeners(n): this;

number

this

TypedEmitter.setMaxListeners


static create(client, opts?): Promise<DisTube>;

Create a DisTube instance and wait for the plugins to be initialized.

Use it when a plugin does asynchronous work in its init method: the constructor cannot await it.

Client

The Discord.js client

DisTubeOptions = {}

Optional options

Promise<DisTube>

The DisTube instance

const distube = await DisTube.create(client, { plugins: [new MyPlugin()] });
readonly static addList: (queue, playlist) => any;

Emitted after DisTube add a new playlist to the playing Queue.

Queue

The guild queue

Playlist

Playlist info

any


readonly static addSong: (queue, song) => any;

Emitted after DisTube add a new song to the playing Queue.

Queue

The guild queue

Song

Added song

any


readonly static debug: (debug) => any;

Emitted to provide debug information from DisTube’s operation. Useful for troubleshooting or logging purposes.

string

Debug message string.

any


readonly static deleteQueue: (queue) => any;

Emitted when the Queue is deleted with any reasons.

Queue

The guild queue

any


readonly static disconnect: (queue) => any;

Emitted when the bot is disconnected to a voice channel.

Queue

The guild queue

any


readonly static empty: (queue) => any;

Emitted when the Queue runs out of songs to play.

Queue

The guild queue

any


readonly static error: (error, queue, song?) => any;

Emitted when DisTube encounters an error while playing songs.

Error

error

Queue

The queue encountered the error

Song<unknown>

The playing song when encountered the error

any


readonly static ffmpegDebug: (debug) => any;

Emitted for logging FFmpeg debug information.

string

Debug message string.

any


readonly static finish: (queue) => any;

Emitted when there is no more song in the queue and Queue#autoplay is false.

Queue

The guild queue

any


readonly static finishSong: (queue, song) => any;

Emitted when DisTube finished a song.

Queue

The guild queue

Song

Finished song

any


readonly static initQueue: (queue) => any;

Emitted when DisTube initialize a queue to change queue default properties.

Queue

The guild queue

any


readonly static noRelated: (queue, error) => any;

Emitted when Queue#autoplay is true, Queue#songs is empty, and DisTube cannot find related songs to play.

Queue

The guild queue

DisTubeError

The error that occurred while looking for related songs

any


readonly static playSong: (queue, song) => any;

Emitted when DisTube play a song. If DisTubeOptions.emitNewSongOnly is true, this event is not emitted when looping a song or next song is the previous one.

Queue

The guild queue

Song

Playing song

any