discord-music-bot icon indicating copy to clipboard operation
discord-music-bot copied to clipboard

Error emitted from the connection: aborted

Open ArthurSouzaC opened this issue 3 years ago • 9 comments

First, the bot could connect to voice channel but couldn't play anything I fixed it using this

Now, bot joins voice channel, starts playing and, after a few seconds, stops playing. Node.js log: "Error emitted from the connection: aborted"

ArthurSouzaC avatar Sep 20 '21 21:09 ArthurSouzaC

It's a known problem with ytdl module. You can try to use play-dl module instead. For me it fixed all of the problems.

pateckii avatar Sep 21 '21 11:09 pateckii

It's a known problem with ytdl module. You can try to use play-dl module instead. For me it fixed all of the problems.

how do i change this? directly into discord-player code?

ArthurSouzaC avatar Sep 21 '21 15:09 ArthurSouzaC

You need to install dev version of discord-player and also play-dl package: cd to main folder with bot then

npm install discord-player@dev
npm install play-dl

In my case every command was a separate .js file, so I edited play.js (play command): add this at the beginning of .js file

const playdl = require("play-dl");

then you find the queue section:

const queue = await client.player.createQueue( guild, {
      metadata: channel
});

and after that you paste:

if(!queue.createStream) {
      queue.createStream = async (track, source, _queue) => {
           if (source === "youtube") {
                 return (await playdl.stream(track.url, process.env.COOKIES)).stream;
           }
       };
 }

The process.env.COOKIES is optional. If you want to use your YouTube cookie then add COOKIES="cookie-here" to your .env file. If you dont want to use cookie, then the return line should look like this:

return (await playdl.stream(track.url)).stream;

pateckii avatar Sep 21 '21 15:09 pateckii

It also might be a problem with age restricted videos. That's why it's good to use cookie. If you want to play age restricted videos then you'll have to add cookie when you're logged in on YouTube and also edit few files of play-dl module.

pateckii avatar Sep 21 '21 15:09 pateckii

@pateckii Your solution seems to work fine!

samusaran avatar Sep 21 '21 18:09 samusaran

Better fix than mine for sure, thanks for sharing @pateckii :3

MeTonaTOR avatar Sep 21 '21 20:09 MeTonaTOR

Thanks for sharing this fix with a different module @pateckii !!! It's super helpful :D On a side note: Would any of y'all know how to get Spotify to work alongside YouTube with play-dl? I see the option is available with the module but I'm having some trouble modifying the code to have the bot play Spotify playlists. Any tips or ideas on how to get this to work is appreciated! And if by some miracle I figure it out I'll definitely share!

bbpink217 avatar Sep 22 '21 15:09 bbpink217

Thanks for sharing this fix with a different module @pateckii !!! It's super helpful :D On a side note: Would any of y'all know how to get Spotify to work alongside YouTube with play-dl? I see the option is available with the module but I'm having some trouble modifying the code to have the bot play Spotify playlists. Any tips or ideas on how to get this to work is appreciated! And if by some miracle I figure it out I'll definitely share!

Oh and for context I already authorized codes for Spotify!

bbpink217 avatar Sep 22 '21 15:09 bbpink217

Thanks for sharing this fix with a different module @pateckii !!! It's super helpful :D On a side note: Would any of y'all know how to get Spotify to work alongside YouTube with play-dl? I see the option is available with the module but I'm having some trouble modifying the code to have the bot play Spotify playlists. Any tips or ideas on how to get this to work is appreciated! And if by some miracle I figure it out I'll definitely share!

@bbpink217 You didn't happen to find a solution that also works for Spotify? 🙂

Zloka avatar Oct 12 '21 17:10 Zloka