Use youtubeCookie: Cookie[]
instead. Guide: YouTube Cookies
Create a new DisTube class.
Discord.JS client
Optional
opts: DisTubeOptionsCustom DisTube options
const Discord = require('discord.js'),
DisTube = require('distube'),
client = new Discord.Client();
// Create a new DisTube
const distube = new DisTube.default(client, { searchSongs: 10 });
// client.DisTube = distube // make it access easily
client.login("Your Discord Bot Token")
```ts
Readonly
clientReadonly
customReadonly
extractorReadonly
filtersReadonly
handlerReadonly
optionsReadonly
queuesReadonly
voicesStatic
defaultDisTube version
Static
versionPrivate
#getAdd related song to the queue
The type can be resolved to give a Queue
The guild queue
Create a custom playlist
Array of url, Song or SearchResult
Optional options
const songs = ["https://www.youtube.com/watch?v=xxx", "https://www.youtube.com/watch?v=yyy"];
const playlist = await distube.createCustomPlaylist(songs, {
member: message.member,
properties: { name: "My playlist name", source: "custom" },
parallel: true
});
distube.play(voiceChannel, playlist, { ... });
```ts
Rest
...args: Parameters<TypedDisTubeEvents[U]>Get the guild queue
The type can be resolved to give a Queue
client.on('message', (message) => {
if (!message.content.startsWith(config.prefix)) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift();
if (command == "queue") {
const queue = distube.getQueue(message);
message.channel.send('Current queue:\n' + queue.songs.map((song, id) =>
`**${id+1}**. [${song.name}](${song.url}) - \`${song.formattedDuration}\``
).join("\n"));
}
});
```ts
Jump to the song number in the queue. The next one is 1, 2,... The previous one is -1, -2,...
The type can be resolved to give a Queue
The song number to play
The new Song will be played
client.on('message', (message) => {
if (!message.content.startsWith(config.prefix)) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift();
if (command == "jump")
distube.jump(message, parseInt(args[0]))
.catch(err => message.channel.send("Invalid song number."));
});
```ts
Pause the guild stream
The type can be resolved to give a Queue
The guild queue
Play / add a song or playlist from url. Search and play a song if it is not a valid url.
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
URL | Search string | Song | SearchResult | Playlist
Optional options
client.on('message', (message) => {
if (!message.content.startsWith(config.prefix)) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift();
if (command == "play")
distube.play(message.member.voice.channel, args.join(" "), {
member: message.member,
textChannel: message.channel,
message
});
});
```ts
Play the previous song
The type can be resolved to give a Queue
The new Song will be played
client.on('message', (message) => {
if (!message.content.startsWith(config.prefix)) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift();
if (command == "previous")
distube.previous(message);
});
```ts
Resume the guild stream
The type can be resolved to give a Queue
The guild queue
Search for a song. You can customize how user answers instead of send a number. Then use DisTube#play to play it.
The string search for
Optional
options: { Search options
Optional
limit?: numberLimit the results
Optional
retried?: booleanOptional
safeWhether or not use safe search (YouTube restricted mode)
Optional
type?: VIDEOType of results (video
or playlist
).
Array of results
Search for a song. You can customize how user answers instead of send a number. Then use DisTube#play to play it.
The string search for
Search options
Optional
limit?: numberLimit the results
Optional
retried?: booleanOptional
safeWhether or not use safe search (YouTube restricted mode)
Type of results (video
or playlist
).
Array of results
Search for a song. You can customize how user answers instead of send a number. Then use DisTube#play to play it.
The string search for
Optional
options: { Search options
Optional
limit?: numberLimit the results
Optional
retried?: booleanOptional
safeWhether or not use safe search (YouTube restricted mode)
Optional
type?: SearchResultTypeType of results (video
or playlist
).
Array of results
Set the playing time to another position
The type can be resolved to give a Queue
Time in seconds
Seeked queue
client.on('message', message => {
if (!message.content.startsWith(config.prefix)) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift();
if (command = 'seek')
distube.seek(message, Number(args[0]));
});
```ts
Set the repeat mode of the guild queue.
Toggle mode (Disabled -> Song -> Queue -> Disabled ->...)
if mode
is undefined
The type can be resolved to give a Queue
Optional
mode: numberThe repeat modes (toggle if undefined
)
The new repeat mode
client.on('message', (message) => {
if (!message.content.startsWith(config.prefix)) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift();
if (command == "repeat") {
let mode = distube.setRepeatMode(message, parseInt(args[0]));
mode = mode ? mode == 2 ? "Repeat queue" : "Repeat song" : "Off";
message.channel.send("Set repeat mode to `" + mode + "`");
}
});
```ts
const { RepeatMode } = require("distube");
let mode;
switch(distube.setRepeatMode(message, parseInt(args[0]))) {
case RepeatMode.DISABLED:
mode = "Off";
break;
case RepeatMode.SONG:
mode = "Repeat a song";
break;
case RepeatMode.QUEUE:
mode = "Repeat all queue";
break;
}
message.channel.send("Set repeat mode to `" + mode + "`");
```ts
Set the guild stream's volume
The type can be resolved to give a Queue
The percentage of volume you want to set
The guild queue
client.on('message', (message) => {
if (!message.content.startsWith(config.prefix)) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift();
if (command == "volume")
distube.setVolume(message, Number(args[0]));
});
```ts
Shuffle the guild queue songs
The type can be resolved to give a Queue
The guild queue
client.on('message', (message) => {
if (!message.content.startsWith(config.prefix)) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift();
if (command == "shuffle")
distube.shuffle(message);
});
```ts
Skip the playing song if there is a next song in the queue. true
and there is no up next song, DisTube will add and
play a related song.
The type can be resolved to give a Queue
The new Song will be played
client.on('message', (message) => {
if (!message.content.startsWith(config.prefix)) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift();
if (command == "skip")
distube.skip(message);
});
```ts
Stop the guild stream
The type can be resolved to give a Queue
client.on('message', (message) => {
if (!message.content.startsWith(config.prefix)) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift();
if (command == "stop") {
distube.stop(message);
message.channel.send("Stopped the queue!");
}
});
```ts
Toggle autoplay mode
The type can be resolved to give a Queue
Autoplay mode state
client.on('message', (message) => {
if (!message.content.startsWith(config.prefix)) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift();
if (command == "autoplay") {
const mode = distube.toggleAutoplay(message);
message.channel.send("Set autoplay mode to `" + (mode ? "On" : "Off") + "`");
}
});
```ts
Emitted after DisTube add a new playlist to the playing Queue.
distube.on("addList", (queue, playlist) => queue.textChannel.send(
`Added \`${playlist.name}\` playlist (${playlist.songs.length} songs) to the queue!`
));
Emitted after DisTube add a new song to the playing Queue.
distube.on("addSong", (queue, song) => queue.textChannel.send(
`Added ${song.name} - \`${song.formattedDuration}\` to the queue by ${song.user}.`
));
Emitted when a Queue is deleted with any reasons.
The guild queue
Emitted when the bot is disconnected to a voice channel.
The guild queue
Emitted when there is no user in the voice channel, DisTubeOptions.leaveOnEmpty
is true
and there is a playing queue.
If there is no playing queue (stopped and DisTubeOptions.leaveOnStop is
false
), it will leave the channel without emitting this event.
The guild queue
distube.on("empty", queue => queue.textChannel.send("Channel is empty. Leaving the channel"))
Emitted when DisTube encounters an error while playing songs.
Text channel where the error is encountered.
The error encountered
distube.on('error', (channel, e) => {
if (channel) channel.send(`An error encountered: ${e}`)
else console.error(e)
})
Emitted for FFmpeg debugging information.
The debug information
Emitted when there is no more song in the queue and Queue#autoplay is
false
. DisTube will leave voice channel if DisTubeOptions.leaveOnFinish is true
.
The guild queue
distube.on("finish", queue => queue.textChannel.send("No more song in queue"));
Emitted when DisTube finished a song.
distube.on("finishSong", (queue, song) => queue.textChannel.send(`${song.name} has finished!`));
Emitted when DisTube initialize a queue to change queue default properties.
The guild queue
distube.on("initQueue", queue => {
queue.autoplay = false;
queue.volume = 100;
});
```ts
Emitted when Queue#autoplay is true
, Queue#songs is empty, and
DisTube cannot find related songs to play.
The guild queue
distube.on("noRelated", queue => queue.textChannel.send("Can't find related video to play."));
```ts
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.
distube.on("playSong", (queue, song) => queue.textChannel.send(
`Playing \`${song.name}\` - \`${song.formattedDuration}\`\nRequested by: ${song.user}`
));
```ts
Emitted when DisTubeOptions.searchSongs bigger than 0, and the search canceled due to DisTubeOptions | DisTubeOptions.searchTimeout.
The user message called play method
The search query
// DisTubeOptions.searchSongs > 0
distube.on("searchCancel", (message) => message.channel.send(`Searching canceled`));
```ts
Emitted when DisTubeOptions.searchSongs bigger than 0, and after the user chose a search result to play.
The user message called play method
The answered message of user
The search query
Emitted when DisTubeOptions.searchSongs bigger than 0, and the search canceled due to user's next message is not a number or out of results range.
The user message called play method
The answered message of user
The search query
// DisTubeOptions.searchSongs > 0
distube.on("searchInvalidAnswer", (message) => message.channel.send(`You answered an invalid number!`));
```ts
Emitted when DisTube cannot find any results for the query.
The user message called play method
The search query
distube.on("searchNoResult", (message, query) => message.channel.send(`No result found for ${query}!`));
```ts
Emitted when DisTubeOptions.searchSongs bigger than 0,
and song param of DisTube#play is invalid url. DisTube will wait for
user's next message to choose a song manually.
The user message called play method
Searched results
The search query
// DisTubeOptions.searchSongs > 0
distube.on("searchResult", (message, results) => {
message.channel.send(`**Choose an option from below**\n${
results.map((song, i) => `**${i + 1}**. ${song.name} - \`${song.formattedDuration}\``).join("\n")
}\n*Enter anything else or wait 60 seconds to cancel*`);
});
```ts
DisTube class