Coder Social home page Coder Social logo

skick1234 / distube Goto Github PK

View Code? Open in Web Editor NEW
418.0 7.0 93.0 19.87 MB

A powerful Discord.js module for simplifying music commands and effortless playback of various sources with integrated audio filters.

Home Page: https://distube.js.org

License: MIT License

Shell 0.19% TypeScript 99.81%
discord music bot discord-js youtube queue-manager queue video soundcloud discord-bot

distube's Introduction

GitHub Workflow Status node-current npm peer dependency version Codecov branch
npm GitHub Repo stars Discord

Buy Me a Coffee at ko-fi.com

DisTube

A powerful Discord.js module for simplifying music commands and effortless playback of various sources with integrated audio filters.

DisTube Support Server - Frequently Asked Questions

Features

  • Easy Integration: Built on top of discord.js v14 and @discordjs/voice.
  • Voice and Queue Management: Handles voice channel connections, disconnections, and manages music queues efficiently.
  • Audio Filters: Offers built-in audio filters (bassboost, echo, karaoke, etc.) and allows for custom filter implementations.
  • Plugin System: Supports extensibility through plugins

    DisTube does not have built-in support for music sources. You need to use plugins to add support for them.

Requirement

Documentation

Read DisTube's definitions, properties and events details in the API Documentation page.

Learn how to build a music bot from scratch with DisTube Guide

List of plugins for supporting various sites

distube's People

Contributors

skick1234 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

distube's Issues

distube#botDisconnect event

I know i can do it with
queue.connection.on("disconnect", () =>
But I'm not sure, where to write this code. As this is an additional event.

addRelatedVideo

Isn't it better, if distube#addRelatedVideo emits addSong event

Add Options for Deafing

Add option for : <voiceState>.setDeaf(<true/false>)

as well as for : <voiceState>.setSelfDeaf(<true/false>)

Thanks ;)

Typescript typings issue

Describe the bug

I am using this module in my typescript bot, and when compiling I get these errors:

Picture

I believe it is an issue with the typings folder for the module.

Expected behavior

The compiler compiles smoothly without any errors.

Additional context

None.

Youtube-dl

When using distube and youtube-dl, most bot hosts are not suited to run python and javascript at the same time. My hosting provider was able to install python3 but because youtube-dl does not support it, it wont run. In my attempts to change the youtube-dl file in distube/youtube-dl/bin, it automatically changed from /usr/bin/python3 to /usr/bin/env python. I tested this on the normal youtube-dl module and it did not change. Any idea on how I could make the youtube-dl module run python3 and not python?

Song Likes and Dislikes displayed as Zero, even on the main bot

Describe the bug
When playing a song and getting the song info, the likes and dislikes are displayed as zero.

Expected behavior
It is supposed to display the actual number of likes and dislikes.

Additional context
It happens on my bot too, not just the DisTube bot, which probably means it's an API issue :>
Screen Shot 2020-12-05 at 10 48 49 AM

rate limit

it rate limits the user very often. it shows the 429 error everyday. whenever i check the logs, it shows that. and returns the same followed by the commands as well!

it should be able to take multiple requests since many user will use the bot and on multiple servers.

MaxListenersExceededWarning

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 disconnect listeners added to [VoiceConnection]. Use emitter.setMaxListeners() to increase limit
at _addListener (events.js:390:17)
at VoiceConnection.addListener (events.js:406:10)

Remove song from queue

Is there a way to remove a song by name or by index from the playlist?

The user would do something like -remove "This Is A Song Name"

we would get the input and do maybe distube.removeFromQueue(args[0])
the parameter would accept a numeric index or a string to search for and remove the first result

SearchOptions

Is your feature request related to a problem? Please describe.
Hi, I wanted to customize the search a bit more, because I don't like my channel full of messages, so there should be a option to enabling the deletion of these messages. Also, I would like to change the amount of results in the list->change possible list of answers.

Describe the solution you'd like
I'd like to have some options in the global "DisTubeOptions" to edit that things :)

Searching songs not working

So, when I try the play command with a URL as a string, it works. But when it's not, it doesn't search the song, and doesn't send a message for a song to pick.

I already have the events and other things right:

const DisTube = require("distube");
client.distube = new DisTube(client, { searchSongs: true, emitNewSongOnly: true, leaveOnFinish: true })

and this:

const status = (queue) => `Volume: \`${queue.volume}%\` || Loop: \`${queue.repeatMode ? queue.repeatMode == 2 ? "Queue" : "Song" : "Off"}\``;

client.distube
    .on("searchResult", (message, result) => {
        let i = 0;
        message.channel.send(`**Choose an option from below**\n${result.map(song => `**${++i}**. ${song.name} - \`${song.formattedDuration}\``).join("\n")}\n*Enter anything else or wait 60 seconds to cancel*`);
    })
    // DisTubeOptions.searchSongs = true
    .on("searchCancel", (message) => message.channel.send(`${client.emotes.error} | Searching canceled`))
    .on("error", (message, err) => message.channel.send(`${client.emotes.error} | An error encountered: ${err}`))

But when I send a non-link argument, it doesn't search songs, need help...

NotPlaying Bug

Describing the bug
Everytime I try to do the skip command with distube.skip(messsage) I get this error

Error: NotPlaying
    at DisTube.skip (D:\discord.js\node_modules\distube\src\DisTube.js:590:23)
    at ClassName.run (D:\discord.js\commands\music\skip.js:33:21)
    at CommandoMessage.run (D:\discord.js\node_modules\discord.js-commando\src\extensions\message.js:222:34)    at CommandDispatcher.handleMessage (D:\discord.js\node_modules\discord.js-commando\src\dispatcher.js:144:32)
    at CommandoClient.<anonymous> (D:\discord.js\node_modules\discord.js-commando\src\client.js:64:51)      
    at CommandoClient.emit (events.js:327:22)
    at MessageCreateAction.handle (D:\discord.js\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)

The expected behavior is the skip command should work perfectly, But its not.
Its also the case with the loop command also

Have a wonderful day <3

Error: NotPlaying

I did everything correctly that I believe. But when my bot joins the voice channel that I am in, a green light appears around the bot as if it's playing audio, but it doesn't play anything. Then I get this error in my CMD.

(node:22944) UnhandledPromiseRejectionWarning: Error: NotPlaying
at DisTube._addToQueue (C:\Users\austi\Documents\Weeb Bot\Weeb-Bot\node_modules\distube\src\DisTube.js:466:23)
at DisTube.addRelatedVideo (C:\Users\austi\Documents\Weeb Bot\Weeb-Bot\node_modules\distube\src\DisTube.js:763:37)
at runMicrotasks ()
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async DisTube._handleSongFinish (C:\Users\austi\Documents\Weeb Bot\Weeb-Bot\node_modules\distube\src\DisTube.js:932:27)
(Use node --trace-warnings ... to show where the warning was created)
(node:22944) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:22944) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Jump Function

Using the Jump Function returns an error saying that jump is not a function.

New DisTube Option: searchResultCount

Is your feature request related to a problem? Please describe.
Sometimes when I use the play command, the embed is too large to send because the search results are too high. I know I can fix this by going into the DisTube file in the node_modules folder but sometimes I cannot access them, so this could be an easier way to change it.

Describe the solution you'd like

client.distube = new DisTube(client, { searchSongs: true, searchResultCount: 10 })

Additional context
lol I spent so much time on this lolol.
Screenshot 2020-12-13 at 7 20 02 PM

Autoplay mode

Autoplay mode plays songs repeatedly, doesn't play new songs after that.

Remove deprecated properties

Please update and fix this

videoDetails.thumbnail.thumbnails will be removed in a near future release, use videoDetails.thumbnails instead.

New parameter on Queue, textChannel

Add a new parameter on queue, textChannel . It is the channel in which the play comnand was used first. i think this is useful if we want to send every success message (rather than the default distube event) to the channel, in which the bot is emiting distube event. We can use something like queue.textChannel.send(".. your message bla bla...")

Autoplay

Describe the bug
Autoplay does not seem to work on any song, but calls the no related song found event.

Expected behavior
Autoplay to play a song if a relatable song is found.

Additional context
Im using the latest version (2.8.6).

Add a Search song option

Is it possible to make a search command instead of making searchSongs: true
If yes pls share the code

Music isn't working anymore

Describe the bug
play(alone) encountered: SyntaxError: Unexpected token < in JSON at position 0

Expected behavior
Joins vc and plays music

Additional context
I copied and pasted the code from the default one and its not working. I think its not me

Now Playing Function

If you guys could add a now playing function into your package. it would be very helpful.

thanks!

Add DisTubeOptions.ytdlOptions

It would be nice if we could have the options:
liveBuffer
dlChunkSize
range

Or due to the fact you are using ytdl that we are allowed to use all ytdl options

Unable to reach

Describe the bug
Can't play songs by title neither by url.

Console output:

(node:9352) UnhandledPromiseRejectionWarning: Error: play(ncs) encountered:
Error parsing info: Unable to retrieve video metadata
    at getWatchPage (D:\Programming\Projects\seconda-ds\BotGenerale\javascript-version\node_modules\ytdl-core\lib\info.js:77:13)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async exports.getBasicInfo (D:\Programming\Projects\seconda-ds\BotGenerale\javascript-version\node_modules\ytdl-core\lib\info.js:86:22)
    at async Map.getOrSet (D:\Programming\Projects\seconda-ds\BotGenerale\javascript-version\node_modules\ytdl-core\lib\cache.js:24:19)
    at async exports.getInfo (D:\Programming\Projects\seconda-ds\BotGenerale\javascript-version\node_modules\ytdl-core\lib\info.js:210:14)
    at async Map.getOrSet (D:\Programming\Projects\seconda-ds\BotGenerale\javascript-version\node_modules\ytdl-core\lib\cache.js:24:19)
    at async DisTube._resolveSong (D:\Programming\Projects\seconda-ds\BotGenerale\javascript-version\node_modules\distube\src\DisTube.js:192:55)
    at async DisTube.play (D:\Programming\Projects\seconda-ds\BotGenerale\javascript-version\node_modules\distube\src\DisTube.js:243:44)
(node:9352) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)`

Expected behavior
The song would play or sending an error to the text channel

Additional context

This is the setup

app.js

const Discord = require("discord.js");
const bot = new Discord.Client();
bot.distube = new DisTube(bot, { searchSongs: false, emitNewSongOnly: true });

play.js

const distube = require("distube");

module.exports = {
  name: "play",
  desc: "Play a song by title or url",
  args: true,
  aliases: ["p"],
  usage: "play [title]",
  async execute(bot, message, args) {
    const string = args.join(" ");
    try {
      bot.distube.play(message, string);
    } catch (err) {
      message.channel.send(err.message);
    }
  },
};

package.json

  "dependencies": {
    "@discordjs/opus": "^0.3.3",
    "discord.js": "^12.4.1",
    "distube": "^2.8.8",
    "dotenv": "^8.2.0",
    "ffmpeg": "0.0.4",
    "ffmpeg-static": "^4.2.7",
    "fluent-ffmpeg": "^2.1.2",
    "node-fetch": "^2.6.1",
    "youtube-dl": "^3.1.0",
    "yt-search": "^2.3.3",
    "ytdl-core": "^4.0.0"
  },

Song.user but tag not <@id>

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
I don't want to use mention, but Song.user using toString(mention format)

Describe the solution you'd like
A clear and concise description of what you want to happen.
Just need Username#tag format, not <@id>(mention) format.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

https://discord.js.org/#/docs/main/master/class/User?scrollTo=tag maybe?

Additional context
Add any other context or screenshots about the feature request here.
Screenshot_20210215-144557_Discord

Sorry for my bad English🙄

Leave after some time

Add a new event where we can customise when the bot will leave. if LeaveOnFinish event is false, the the bot will leave the voice channel after some time.

When the song's likes or dislikes is zero, it displays it as NaN

Describe the bug
When the song's likes or dislikes are zero, it displays it as NaN.

Expected behavior
It should say 0 instead.

Additional Comments
I know I can just replace it with 0, but shouldn't the API say 0 if the song has 0 likes or dislikes, why's it saying NaN?

Getting an error on cookie.

This is what i did :
const distube = new DisTube(client, {emitNewSongOnly: true, leaveOnStop: false, youtubeCookie:"XXXX", youtubeIdentityToken:"XXXX" });

And it's returning this error when i try to play any song :
DisTube: Downloaded youtube-dl 2020.09.20 (node:9760) UnhandledPromiseRejectionWarning: Error: Error parsing info: Cookie header used in request, but unable to retrieve video metadata

Once a Song starts it will delete the QUEUE

  // DisTube event listeners, more in the documentation page
  client.distube
      .on("playSong", (message, queue, song) => {

        message.channel.send(new MessageEmbed()
          .setTitle("Playing :notes: " + song.name)
          .setURL(song.url)
          .setColor(ee.color)
          .addField("Duration", `\`${song.formattedDuration}\``)
          .addField("QueueStatus", status(queue))
          .setThumbnail(song.thumbnail)
          .setFooter(`Requested by: ${song.user.tag}`, song.user.displayAvatarURL({dynamic: true}))
      ).then(async msg => {
        console.log(queue) //--> gives queue
        console.log(client.distube.getQueue(message)) //gives undefined

Cannot read property 'on' of null

Describe the bug
If i use seek command, then skip a song, I'm getting this Error. Otherwise it is working. If i skip without using seek Command before, no Error
TypeError: Cannot read property 'on' of null
at playingStart (/app/src/events/playSong.js:239:33)
at runMicrotasks ()
at processTicksAndRejections (internal/process/task_queues.js:93:5)

Here is the code
I'm using queue.dispatcher.on("finish", () =>
I've tried using queue.connection.dispatcher.on("finish", () =>
And
queue.connection.on("finish", () =>

Sorry for bad English

Proxy feature

Is your feature request related to a problem? Please describe.
No problem

Describe the solution you'd like
the option inside the constructor to use a PROXY
i.e {proxy: ""} etc, and then use the proxy arg inside of youtube-dl

Describe alternatives you've considered
i was just gonna fork this and do it myself, but i figured id ask
if possible to add this before i went ahead!

Additional context
Add any other context or screenshots about the feature request here.

Sends multiple messages

when i do the play command it works fine the first time but the second time i do it it sends the message twice?

Suggestion

Maybe add a function like rewind which will take the playing song back/forward to x seconds

Bad Audio Quality

Is there some kind of filter option to increase the quality or something? The audio is almost something that i don't wanna listen to. My Internets perfect and i got all the requirements installed.

Playing Issue

Describe the bug
The bug is an issue where I get an error

(node:4016) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'url' of undefined
at StreamDispatcher.<anonymous> (/home/container/node_modules/distube/src/DisTube.js:782:51)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:97:5)

which occurs sometimes when using the play cmd

Expected behavior
No errors should be thrown.

Additional context
I am using version 2.1.4

Range error when playing songs

When running the play command (usually but not always when passing in a link as the message) an error is thrown. This doesnt happen regularly and I cannot recreate it on purpose.

RangeError: Source is too large

/node_modules/opusscript/build/opusscript_native_wasm.js:8
var Module=typeof Module!=="undefined"?Module:{};var moduleOverrides={};var key;for(key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}Module["arguments"]=[];Module["thisProgram"]="./this.program";Module["quit"]=function(status,toThrow){throw toThrow};Module["preRun"]=[];Module["postRun"]=[];var ENVIRONMENT_IS_WEB=false;var ENVIRONMENT_IS_WORKER=false;var ENVIRONMENT_IS_NODE=false;var ENVIRONMENT_HAS_NODE=false;var ENVIRONMENT_IS_SHELL=false;ENVIRONMENT_IS_WEB=typeof window==="object";ENVIRONMENT_IS_WORKER=typeof importScripts==="function";ENVIRONMENT_HAS_NODE=typeof process==="object"&&typeof process.versions==="object"&&typeof process.versions.node==="string";ENVIRONMENT_IS_NODE=ENVIRONMENT_HAS_NODE&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER;var scriptDirectory="";function locateFile(path){if(Module["locateF
abort(RangeError: Source is too large). Build with -s ASSERTIONS=1 for more info.

This then crashes the entire bot.

The distube music bot portion of the bot.

const distube = new DisTube(client, { searchSongs: true, emitNewSongOnly: true, highWaterMark: 1 << 25 });

  client.on("message", async (message) => {
    if (message.author.bot) return;
    if (!message.content.startsWith(prefix)) return;
    const args = message.content.slice(prefix.length).trim().split(/ +/g);
    const command = args.shift().toLowerCase();
    
    if (command == "play"){
        distube.play(message, args.join(" "));
    }

    if (["repeat", "loop"].includes(command)){
        distube.setRepeatMode(message, parseInt(args[0]));
    }

    if (command == "stop") {
        distube.stop(message);
        message.channel.send("Stopped the music!");
    }

    if (command == "skip"){
      distube.skip(message);
      message.channel.send("Skipped the music!");
    }

    if (command == "queue") {
        let queue = distube.getQueue(message);
        message.channel.send('Current queue:\n' + queue.songs.map((song, id) =>
            `**${id + 1}**. ${song.name} - \`${song.formattedDuration}\``
        ).join("\n"));
    }

    if (command === "toggleautoplay"){
      var mode = distube.toggleAutoplay(message);
      message.channel.send("Set autoplay mode to `" + (mode ? "On" : "Off") + "`");
    }

    if (command === "playskip"){
        distube.playSkip(message, args.join(" "));
    }

    if ([`3d`, `bassboost`, `echo`, `karaoke`, `nightcore`, `vaporwave`].includes(command)) {
        let filter = distube.setFilter(message, command);
        message.channel.send("Current queue filter: " + (filter || "Off"));
    }

  });

const status = (queue) => `Volume: \`${queue.volume}%\` | Filter: \`${queue.filter || "Off"}\` | Loop: \`${queue.repeatMode ? queue.repeatMode == 2 ? "All Queue" : "This Song" : "Off"}\` | Autoplay: \`${queue.autoplay ? "On" : "Off"}\``;

  distube
    .on("playSong", (message, queue, song) => message.channel.send(
        `Playing \`${song.name}\` - \`${song.formattedDuration}\`\nRequested by: ${song.user}\n${status(queue)}`
    ))
    .on("addSong", (message, queue, song) => message.channel.send(
        `Added ${song.name} - \`${song.formattedDuration}\` to the queue by ${song.user}`
    ))
    .on("playList", (message, queue, playlist, song) => message.channel.send(
        `Play \`${playlist.title}\` playlist (${playlist.total_items} songs).\nRequested by: ${song.user}\nNow playing \`${song.name}\` - \`${song.formattedDuration}\`\n${status(queue)}`
    ))
    .on("addList", (message, queue, playlist) => message.channel.send(
        `Added \`${playlist.title}\` playlist (${playlist.total_items} songs) to queue\n${status(queue)}`
    ))

    .on("searchResult", (message, result) => {
        let i = 0;
        message.channel.send(`**Choose an option from below**\n${result.map(song => `**${++i}**. ${song.title} - \`${song.duration}\``).join("\n")}\n*Enter anything else or wait 60 seconds to cancel*`);
    })

    .on("searchCancel", (message) => message.channel.send(`Searching canceled`))
    .on("error", (message, err) => message.channel.send(
        "An error encountered: " + err
    ));

FATAL: kernel too old

I just reinstalled all dependencies:
"@discordjs/opus": "^0.3.3", "discord.js": "^12.3.1", "distube": "^2.8.7", "ffmpeg-static": "^4.2.7", "opusscript": "0.0.7", "request": "^2.88.2"
But now Im getting the message "FATAL: kernel too old" and cycled play command. Distube just load new songs one by one without playing anything.

Jump

Found the problem with the other issue, when using jump(msg, 1) with nothing in the queue it will act like skip, and not return an error where it would say that 1 isnt in the queue. Is this intented?

Emit playSong event only if the Song is playable

Describe the bug
I'm trying to play https://youtu.be/f1tN1MSWs20 this song. It says video unavailable but it still sent play message.

Expected behavior
When it cannot play a song, it should not send play message . It should just send the error message.

Additional context
I've tried many times to play the song, but every time same problem.

How do I disable autoplay?

Main problem
I was making a bot using the Distube NPM package, but then it says "Autoplay: On"

Expected behavior
I expected it to not have any autoplay.

Allow array of search strings in playCustomPlaylist

I'm trying to play songs from a spotify playlist url by getting the youtube url of every song in it with ytsr and then passing the array of urls to the playCustomPlaylist method. The problem with this is that it creates too many requests at once to youtube and they end up blocking my ip temporarily

Something I propose is to let playCustomPlaylist accept search strings, and let distube perform the search of metadata just when the player is about to play a song.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.