Androz2091 / discord-player

🎧 Complete framework to simplify the implementation of music commands using discord.js v14
https://discord-player.js.org/
MIT License
605 stars 192 forks source link

Bot won't play any songs/Song ending early #1639

Closed febkosq8 closed 1 year ago

febkosq8 commented 1 year ago

Describe the bug When I run the bot on my local Windows 11 machine, everything works fine.

But when the bot runs on Ubuntu 22, the bot will skip playing and directly go to the finish state. I host my bot in Heroku (running on Ubuntu 22.04 stack). This issue doesn't exist in Ubuntu 20 (As a workaround downgrading heroku stack to 20 fixes this issue).

Current list of affected Linux distro :

  1. Ubuntu 22.04
  2. Arch 5.15.79.1-microsoft-standard-WSL2
  3. CentOS Stream release 8
  4. 6.1.1-arch1-1

index.js

....
const { Player } = require("discord-player");
const player = new Player(client);
....

play.js

....
const query = interaction.options.getString("query");
const searchResult = await player.search(query);

if (!searchResult.hasTracks()) {
            await interaction.editReply(`We found no tracks for ${query}!`);
            return;
            } else {
                await player.play(interaction.member.voice.channel, searchResult, {
                    nodeOptions: {
                        metadata: interaction.channel,
                        bufferingTimeout: 15000,
                        leaveOnStop: true,
                        leaveOnStopCooldown: 5000,
                        leaveOnEnd: true,
                        leaveOnEndCooldown: 15000,
                        leaveOnEmpty: true,
                        leaveOnEmptyCooldown: 300000,
                        skipOnNoStream: true,
                    },
                });
            }

await interaction.followUp({content: `⏱ | Loading your ${searchResult.playlist ? "playlist" : "track"}`,});
....

Attaching debug event to the player below :

Ubuntu 22.04

[DEBUG] Discord Player Debug Event
Preparing final stream config: {
"disableBiquad": false,
"disableEqualizer": false,
"disableVolume": false,
"disableFilters": false,
"disableResampler": false,
"sampleRate": 48000,
"eq": [],
"defaultFilters": [],
"volume": 100,
"transitionMode": false,
"ffmpegFilters": "",
"seek": 0
}
[DEBUG] Discord Player Debug Event
Initiating DSP filters pipeline...
[DEBUG] Discord Player Debug Event
Executing onAfterCreateStream hook...
[DEBUG] Discord Player Debug Event
Preparing AudioResource...
[DEBUG] Discord Player Debug Event
Initializing audio player...
[DEBUG] Discord Player Debug Event
state change:
from {"status":"idle","resource":false,"stepTimeout":false}
to {"status":"buffering","resource":true,"stepTimeout":false}
[DEBUG] Discord Player Debug Event
Dispatching audio...
[DEBUG] Discord Player Debug Event
Player triggered for Track {"title":"The Weeknd & Ariana Grande - Die For You (Remix)","reason":"normal"}
[DEBUG] Discord Player Debug Event
state change:
from {"status":"buffering","resource":true,"stepTimeout":false}
to {"status":"playing","missedFrames":0,"playbackDuration":0,"resource":true,"stepTimeout":false}
[DEBUG] Discord Player Debug Event
[NW] [WS] >> {"op":5,"d":{"speaking":1,"delay":0,"ssrc":140130}}
[DEBUG] Discord Player Debug Event
[NW] [WS] >> {"op":5,"d":{"speaking":0,"delay":0,"ssrc":140130}}
[DEBUG] Discord Player Debug Event
Track {"title":"The Weeknd & Ariana Grande - Die For You (Remix)","isTransitionMode":false} was marked as finished
[DEBUG] Discord Player Debug Event
Adding track to history and emitting finish event since transition mode is disabled...
[DEBUG] Discord Player Debug Event
No more tracks left in the queue to play and repeat mode is off, initiating #emitEnd()
[DEBUG] Discord Player Debug Event
state change:
from {"status":"playing","missedFrames":0,"playbackDuration":120,"resource":true,"stepTimeout":false}
to {"status":"idle","resource":false,"stepTimeout":false}
[DEBUG] Discord Player Debug Event
[NW] [WS] >> {"op":0,"d":{"server_id":"473160079739322368","user_id":"732230135671029831","session_id":"cc5bf168a85bab4fc3146fa8ed1f3825","token":"8b9a382096aef2eb"}}
[DEBUG] Discord Player Debug Event
Detected @discordjs/voice version 0.14.0 which needs keepAlive patch, applying patch...
[DEBUG] Discord Player Debug Event
[NW] state change:
from {"code":0,"ws":true,"connectionOptions":{"endpoint":"rotterdam5312.discord.media:443","serverId":"473160079739322368","token":"8b9a382096aef2eb","sessionId":"cc5bf168a85bab4fc3146fa8ed1f3825","userId":"732230135671029831"},"udp":false}
to {"code":1,"ws":true,"connectionOptions":{"endpoint":"rotterdam5312.discord.media:443","serverId":"473160079739322368","token":"8b9a382096aef2eb","sessionId":"cc5bf168a85bab4fc3146fa8ed1f3825","userId":"732230135671029831"},"udp":false}
[DEBUG] Discord Player Debug Event
[NW] [WS] << {"op":8,"d":{"v":4,"heartbeat_interval":13750.0}}
[DEBUG] Discord Player Debug Event
[NW] [WS] << {"op":2,"d":{"streams":[{"type":"video","ssrc":140131,"rtx_ssrc":140132,"rid":"","quality":0,"active":false}],"ssrc":140130,"port":50007,"modes":["aead_aes256_gcm_rtpsize","aead_aes256_gcm","aead_xchacha20_poly1305_rtpsize","xsalsa20_poly1305_lite_rtpsize","xsalsa20_poly1305_lite","xsalsa20_poly1305_suffix","xsalsa20_poly1305"],"ip":"66.22.197.156","experiments":["fixed_keyframe_interval"]}}
[DEBUG] Discord Player Debug Event
Detected @discordjs/voice version 0.14.0 which needs keepAlive patch, applying patch...
[DEBUG] Discord Player Debug Event
[NW] state change:
from {"code":1,"ws":true,"connectionOptions":{"endpoint":"rotterdam5312.discord.media:443","serverId":"473160079739322368","token":"8b9a382096aef2eb","sessionId":"cc5bf168a85bab4fc3146fa8ed1f3825","userId":"732230135671029831"},"udp":false}
to {"code":2,"ws":true,"connectionOptions":{"endpoint":"rotterdam5312.discord.media:443","serverId":"473160079739322368","token":"8b9a382096aef2eb","sessionId":"cc5bf168a85bab4fc3146fa8ed1f3825","userId":"732230135671029831"},"udp":true,"connectionData":{"ssrc":140130}}
[DEBUG] Discord Player Debug Event
[NW] [WS] << {"op":5,"d":{"user_id":"176002676696416257","ssrc":140032,"speaking":1}}
[DEBUG] Discord Player Debug Event
[NW] [WS] >> {"op":1,"d":{"protocol":"udp","data":{"address":"3.250.223.20","port":50105,"mode":"xsalsa20_poly1305_lite"}}}
[DEBUG] Discord Player Debug Event
Detected @discordjs/voice version 0.14.0 which needs keepAlive patch, applying patch...
[DEBUG] Discord Player Debug Event
[NW] state change:
from {"code":2,"ws":true,"connectionOptions":{"endpoint":"rotterdam5312.discord.media:443","serverId":"473160079739322368","token":"8b9a382096aef2eb","sessionId":"cc5bf168a85bab4fc3146fa8ed1f3825","userId":"732230135671029831"},"udp":true,"connectionData":{"ssrc":140130}}
to {"code":3,"ws":true,"connectionOptions":{"endpoint":"rotterdam5312.discord.media:443","serverId":"473160079739322368","token":"8b9a382096aef2eb","sessionId":"cc5bf168a85bab4fc3146fa8ed1f3825","userId":"732230135671029831"},"udp":true,"connectionData":{"ssrc":140130}}
[DEBUG] Discord Player Debug Event
[NW] [WS] << {"op":4,"d":{"video_codec":"H264","secret_key":[205,179,64,220,193,224,230,46,78,79,30,67,140,16,214,93,28,155,4,167,243,3,7,228,20,48,122,124,247,197,163,56],"mode":"xsalsa20_poly1305_lite","media_session_id":"e98e5b83cc02829367fafbdb7570e5ef","audio_codec":"opus"}}
[DEBUG] Discord Player Debug Event
Detected @discordjs/voice version 0.14.0 which needs keepAlive patch, applying patch...
[DEBUG] Discord Player Debug Event
[NW] state change:
from {"code":3,"ws":true,"connectionOptions":{"endpoint":"rotterdam5312.discord.media:443","serverId":"473160079739322368","token":"8b9a382096aef2eb","sessionId":"cc5bf168a85bab4fc3146fa8ed1f3825","userId":"732230135671029831"},"udp":true,"connectionData":{"ssrc":140130}}
to {"code":4,"ws":true,"connectionOptions":{"endpoint":"rotterdam5312.discord.media:443","serverId":"473160079739322368","token":"8b9a382096aef2eb","sessionId":"cc5bf168a85bab4fc3146fa8ed1f3825","userId":"732230135671029831"},"udp":true,"connectionData":{"ssrc":140130,"encryptionMode":"xsalsa20_poly1305_lite","secretKey":{"0":205,"1":179,"2":64,"3":220,"4":193,"5":224,"6":230,"7":46,"8":78,"9":79,"10":30,"11":67,"12":140,"13":16,"14":214,"15":93,"16":28,"17":155,"18":4,"19":167,"20":243,"21":3,"22":7,"23":228,"24":20,"25":48,"26":122,"27":124,"28":247,"29":197,"30":163,"31":56},"sequence":21114,"timestamp":841733103,"nonce":0,"nonceBuffer":{"type":"Buffer","data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},"speaking":false,"packetsPlayed":0}}
[DEBUG] Discord Player Debug Event
Stream extraction was successful for Track { title: The Weeknd & Ariana Grande - Die For You (Remix), url: https://www.youtube.com/watch?v=_MQjVzZSLNw } (Extractor: com.discord-player.youtubeextractor)
[DEBUG] Discord Player Debug Event
GuildQueue initialized for guild Makeshift Gaming (ID: 473160079739322368)
[DEBUG] Discord Player Debug Event
Connecting to voice channel VOICE 1 (ID: 750292121826754560)
[DEBUG] Discord Player Debug Event
Detected @discordjs/voice version 0.14.0 which needs keepAlive patch, applying patch...
[DEBUG] Discord Player Debug Event
Received play request from guild Makeshift Gaming (ID: 473160079739322368)
[DEBUG] Discord Player Debug Event
Requested option requires to play the track, initializing...
[DEBUG] Discord Player Debug Event
Initiating stream extraction process...
[DEBUG] Discord Player Debug Event
Executing onBeforeCreateStream hook (QueryType: youtubeSearch)...
[DEBUG] Discord Player Debug Event
Failed to get stream from onBeforeCreateStream!
[DEBUG] Discord Player Debug Event
Attempting to extract stream for Track { title: The Weeknd & Ariana Grande - Die For You (Remix), url: https://www.youtube.com/watch?v=_MQjVzZSLNw } using registered extractors
[DEBUG] Discord Player Debug Event
Detected @discordjs/voice version 0.14.0 which needs keepAlive patch, applying patch...
[DEBUG] Discord Player Debug Event
[NW] [WS] << {"op":5,"d":{"user_id":"176002676696416257","ssrc":140032,"speaking":1}}
[INFO] A interaction for : play was triggered in Guild : xxxx / xxxxx by User : Febkosq8#8685 / 407819516513484801
[DEBUG] Discord Player Debug Event
[NW] [WS] << {"op":5,"d":{"user_id":"407819516513484801","ssrc":139803,"speaking":1}}

Result when play command is used: The bot joins the VC and leaves in a second. It also triggers the following events in order : audioTrackAdd > playerStart > emptyQueue > disconnect.


Windows 11 22H2

[DEBUG] Discord Player Debug Event
GuildQueue initialized for guild Makeshift Gaming (ID: 473160079739322368)
[DEBUG] Discord Player Debug Event
Connecting to voice channel VOICE 1 (ID: 750292121826754560)
[DEBUG] Discord Player Debug Event
Detected @discordjs/voice version 0.14.0 which needs keepAlive patch, applying patch...
[DEBUG] Discord Player Debug Event
Received play request from guild Makeshift Gaming (ID: 473160079739322368)
[DEBUG] Discord Player Debug Event
Requested option requires to play the track, initializing...
[DEBUG] Discord Player Debug Event
Initiating stream extraction process...
[DEBUG] Discord Player Debug Event
Executing onBeforeCreateStream hook (QueryType: youtubeSearch)...
[DEBUG] Discord Player Debug Event
Failed to get stream from onBeforeCreateStream!
[DEBUG] Discord Player Debug Event
Attempting to extract stream for Track { title: The Weeknd & Ariana Grande - Die For You (Remix), url: https://www.youtube.com/watch?v=_MQjVzZSLNw } using registered extractors
[DEBUG] Discord Player Debug Event
Detected @discordjs/voice version 0.14.0 which needs keepAlive patch, applying patch...
[DEBUG] Discord Player Debug Event
[NW] [WS] >> {"op":0,"d":{"server_id":"473160079739322368","user_id":"1030967755274473522","session_id":"e7adfc00d547375d387174b6a6bec45c","token":"64bbb0eed02f5ccd"}}
[DEBUG] Discord Player Debug Event
Detected @discordjs/voice version 0.14.0 which needs keepAlive patch, applying patch...
[DEBUG] Discord Player Debug Event
[NW] state change:
from {"code":0,"ws":true,"connectionOptions":{"endpoint":"rotterdam5312.discord.media:443","serverId":"473160079739322368","token":"64bbb0eed02f5ccd","sessionId":"e7adfc00d547375d387174b6a6bec45c","userId":"1030967755274473522"},"udp":false}
to {"code":1,"ws":true,"connectionOptions":{"endpoint":"rotterdam5312.discord.media:443","serverId":"473160079739322368","token":"64bbb0eed02f5ccd","sessionId":"e7adfc00d547375d387174b6a6bec45c","userId":"1030967755274473522"},"udp":false}
[DEBUG] Discord Player Debug Event
[NW] [WS] << {"op":8,"d":{"v":4,"heartbeat_interval":13750.0}}
[DEBUG] Discord Player Debug Event
[NW] [WS] << {"op":2,"d":{"streams":[{"type":"video","ssrc":140351,"rtx_ssrc":140352,"rid":"","quality":0,"active":false}],"ssrc":140350,"port":50007,"modes":["aead_aes256_gcm_rtpsize","aead_aes256_gcm","aead_xchacha20_poly1305_rtpsize","xsalsa20_poly1305_lite_rtpsize","xsalsa20_poly1305_lite","xsalsa20_poly1305_suffix","xsalsa20_poly1305"],"ip":"66.22.197.156","experiments":["fixed_keyframe_interval"]}}
[DEBUG] Discord Player Debug Event
Detected @discordjs/voice version 0.14.0 which needs keepAlive patch, applying patch...
[DEBUG] Discord Player Debug Event
[NW] state change:
from {"code":1,"ws":true,"connectionOptions":{"endpoint":"rotterdam5312.discord.media:443","serverId":"473160079739322368","token":"64bbb0eed02f5ccd","sessionId":"e7adfc00d547375d387174b6a6bec45c","userId":"1030967755274473522"},"udp":false}
to {"code":2,"ws":true,"connectionOptions":{"endpoint":"rotterdam5312.discord.media:443","serverId":"473160079739322368","token":"64bbb0eed02f5ccd","sessionId":"e7adfc00d547375d387174b6a6bec45c","userId":"1030967755274473522"},"udp":true,"connectionData":{"ssrc":140350}}
[DEBUG] Discord Player Debug Event
[NW] [WS] >> {"op":1,"d":{"protocol":"udp","data":{"address":"86.9.62.109","port":55093,"mode":"xsalsa20_poly1305_lite"}}}
[DEBUG] Discord Player Debug Event
Detected @discordjs/voice version 0.14.0 which needs keepAlive patch, applying patch...
[DEBUG] Discord Player Debug Event
[NW] state change:
from {"code":2,"ws":true,"connectionOptions":{"endpoint":"rotterdam5312.discord.media:443","serverId":"473160079739322368","token":"64bbb0eed02f5ccd","sessionId":"e7adfc00d547375d387174b6a6bec45c","userId":"1030967755274473522"},"udp":true,"connectionData":{"ssrc":140350}}
to {"code":3,"ws":true,"connectionOptions":{"endpoint":"rotterdam5312.discord.media:443","serverId":"473160079739322368","token":"64bbb0eed02f5ccd","sessionId":"e7adfc00d547375d387174b6a6bec45c","userId":"1030967755274473522"},"udp":true,"connectionData":{"ssrc":140350}}
[DEBUG] Discord Player Debug Event
[NW] [WS] << {"op":4,"d":{"video_codec":"H264","secret_key":[120,206,36,108,200,34,250,229,194,165,180,69,121,33,140,25,114,92,88,36,235,121,160,187,255,9,185,210,10,85,17,165],"mode":"xsalsa20_poly1305_lite","media_session_id":"e98e5b83cc02829367fafbdb7570e5ef","audio_codec":"opus"}}
[DEBUG] Discord Player Debug Event
Detected @discordjs/voice version 0.14.0 which needs keepAlive patch, applying patch...
[DEBUG] Discord Player Debug Event
[NW] state change:
from {"code":3,"ws":true,"connectionOptions":{"endpoint":"rotterdam5312.discord.media:443","serverId":"473160079739322368","token":"64bbb0eed02f5ccd","sessionId":"e7adfc00d547375d387174b6a6bec45c","userId":"1030967755274473522"},"udp":true,"connectionData":{"ssrc":140350}}
to {"code":4,"ws":true,"connectionOptions":{"endpoint":"rotterdam5312.discord.media:443","serverId":"473160079739322368","token":"64bbb0eed02f5ccd","sessionId":"e7adfc00d547375d387174b6a6bec45c","userId":"1030967755274473522"},"udp":true,"connectionData":{"ssrc":140350,"encryptionMode":"xsalsa20_poly1305_lite","secretKey":{"0":120,"1":206,"2":36,"3":108,"4":200,"5":34,"6":250,"7":229,"8":194,"9":165,"10":180,"11":69,"12":121,"13":33,"14":140,"15":25,"16":114,"17":92,"18":88,"19":36,"20":235,"21":121,"22":160,"23":187,"24":255,"25":9,"26":185,"27":210,"28":10,"29":85,"30":17,"31":165},"sequence":26724,"timestamp":3761747370,"nonce":0,"nonceBuffer":{"type":"Buffer","data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]},"speaking":false,"packetsPlayed":0}}
[DEBUG] Discord Player Debug Event
Stream extraction was successful for Track { title: The Weeknd & Ariana Grande - Die For You (Remix), url: https://www.youtube.com/watch?v=_MQjVzZSLNw } (Extractor: com.discord-player.youtubeextractor)
[DEBUG] Discord Player Debug Event
Preparing final stream config: {
  "disableBiquad": false,
  "disableEqualizer": false,
  "disableVolume": false,
  "disableFilters": false,
  "disableResampler": false,
  "sampleRate": 48000,
  "eq": [],
  "defaultFilters": [],
  "volume": 100,
  "transitionMode": false,
  "ffmpegFilters": "",
  "seek": 0
}
[DEBUG] Discord Player Debug Event
Initiating DSP filters pipeline...
[DEBUG] Discord Player Debug Event
Executing onAfterCreateStream hook...
[DEBUG] Discord Player Debug Event
Preparing AudioResource...
[DEBUG] Discord Player Debug Event
Initializing audio player...
[DEBUG] Discord Player Debug Event
state change:
from {"status":"idle","resource":false,"stepTimeout":false}
to {"status":"buffering","resource":true,"stepTimeout":false}
[DEBUG] Discord Player Debug Event
Dispatching audio...
[INFO] A interaction for : play was triggered in Guild : xxxx / xxxx by User : Febkosq8#8685 / 407819516513484801
[DEBUG] Discord Player Debug Event
Player triggered for Track {"title":"The Weeknd & Ariana Grande - Die For You (Remix)","reason":"normal"}
[DEBUG] Discord Player Debug Event
state change:
from {"status":"buffering","resource":true,"stepTimeout":false}
to {"status":"playing","missedFrames":0,"playbackDuration":0,"resource":true,"stepTimeout":false}
[DEBUG] Discord Player Debug Event
[NW] [WS] >> {"op":5,"d":{"speaking":1,"delay":0,"ssrc":140350}}

Result when play command is used: The bot joins the VC and starts to play the requested music. It also triggers the following events in order : audioTrackAdd > playerStart.

To Reproduce

Steps to reproduce the behavior:

  1. Run the bot on Ubuntu 22
  2. Use the play command to queue a song
  3. Bot will join the VC and leave immediately.

Expected behavior

  1. Run the bot on Ubuntu 22
  2. Use the play command to queue a song
  3. Bot will join the VC and start playing the requested song.

Screenshots

Please complete the following information:

Additional context

The only changing factor I know is the ffmpeg build being used but Heroku same buildpack on stack 20 works fine.

Greensky-gs commented 1 year ago

I have this issue too, on Ubuntu 22 like febkosq8, the bot just connects and skip to the song end, emitting the event

febkosq8 commented 1 year ago

Update : Tried playing a local file as shown in LINK and that seems to work fine both on Heroku/Windows.

Sir-Ayd commented 1 year ago

I have the same issue in which bot can't play music on Heroku when using discord-player v6

Mylloon commented 1 year ago

I can confirm this issue, tried on :

Local file was also working Docker image node:19.7.0-bullseye-slim is working

twlite commented 1 year ago

Are you guys by chance using es modules? 🤔

febkosq8 commented 1 year ago

Are you guys by chance using es modules? 🤔

Personally no.

Mylloon commented 1 year ago

I do

ddemile commented 1 year ago

I do

samusaran commented 1 year ago

Same issue on CentOS Stream release 8.

It worked before on discord-player v5 (i used Androz2091 discord-music-bot directly, now I'm upgrading it to v6)

pankofufu commented 1 year ago

running linux on kernel 6.1.1-arch1-1, discord-player 6.1.0 bot won't play any music for me either

samusaran commented 1 year ago

So it seems it's more of a linux problem than an Ubuntu specific issue.

febkosq8 commented 1 year ago

But not all Linux distros. debian on wsl worked fine. So does Ubuntu 20.04.

pankofufu commented 1 year ago

i can't reproduce this on macOS 12.6.3 (UNIX based OS) so this is a Linux problem

samusaran commented 1 year ago

Could it be node-related? I'm still on node 16.

Im happy to help troubleshooting on my system.

Mylloon commented 1 year ago

Could it be node-related? I'm still on node 16.

Im happy to help troubleshooting on my system.

Nop, working on docker image node:19.7.0-bullseye-slim Imo its more of a problem with recent versions of Linux, as older versions seem to work fine so far

samusaran commented 1 year ago

That's what i meant. Maybe it's an issue with older versions of node. I'm on node 16 so...

Sent from Ninehttp://www.9folders.com/


Da: Mylloon @.***> Inviato: domenica 12 marzo 2023 16:21 A: Androz2091/discord-player Cc: Alessandro Losi; Comment Oggetto: Re: [Androz2091/discord-player] Bot won't play any songs if running on some Linux distros (Issue #1639)

Could it be node-related? I'm still on node 16.

Im happy to help troubleshooting on my system.

Nop, working on docker image node:19.7.0-bullseye-slim

— Reply to this email directly, view it on GitHubhttps://github.com/Androz2091/discord-player/issues/1639#issuecomment-1465226424, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AACG7N2FCNXP7VG35AM2Z73W3XSXJANCNFSM6AAAAAAVPQEYXM. You are receiving this because you commented.Message ID: @.***>

Mylloon commented 1 year ago

For me it wasn't working for the alpine version of node 19 (node:19.4.0-alpine3.16) so I don't think it's node related, but maybe, Idk

Sparoney commented 1 year ago

I also had this problem on Ubuntu 22, I got it to work by running the bot in a Docker image, specifically ghcr.io/parkervcp/yolks:nodejs_18 for the Pterodactyl Panel, which appears to be based on the node:18-bullseye-slim image

Eaterminer commented 1 year ago

Have any tempory fixes been found?

Edit: Trying above Fix, Didn't Notice it 0_0

ghxst0x1 commented 1 year ago

It didn't work for me in the node:18-alpine image. So I used node:19.7.0-bullseye-slim as @Mylloon suggested above. It works for me now without the issue. I use railway.app to host the project. Since the node version is different from the image I used, I think it is because of the node version installed in the distro that causing the problem. I don't know if that is the case just a hunch.

samusaran commented 1 year ago

It's not node related. On centos stream i've tried node 16, 18 and 19 (all with the respective latest minors) and nothing changed.

Sent from Ninehttp://www.9folders.com/


Da: Karthik Raj @.***> Inviato: sabato 18 marzo 2023 06:36 A: Androz2091/discord-player Cc: Alessandro Losi; Comment Oggetto: Re: [Androz2091/discord-player] Bot won't play any songs if running on some Linux distros (Issue #1639)

It didn't work for me in the node:18-alpine image. So I used node:19.7.0-bullseye-slim as @Mylloonhttps://github.com/Mylloon suggested above. It works for me now without the issue. I use railway.app to host the project. Since the node version is different from the image I used, I think it is because of the node version installed in the distro that causing the problem. I don't know if that is the case just a hunch.

— Reply to this email directly, view it on GitHubhttps://github.com/Androz2091/discord-player/issues/1639#issuecomment-1474730002, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AACG7N7GMBG5QZNXEA4DWQLW4VCXJANCNFSM6AAAAAAVPQEYXM. You are receiving this because you commented.Message ID: @.***>

MsVoxxie commented 1 year ago

Same issue here on ubuntu 22.04. Any news on this?

tuomonen commented 1 year ago

I did not realize that this was an issue until I saw messages in Zerio's Discord channel. The problem relates to audioTrackAdd and audioTracksAdd listeners. I have solved this by adding if condition to listeners:

player.events.on('audioTrackAdd', (queue, track) => { if (queue.node.isPlaying()){ queue.metadata.channel.send(``Added to the queue ${track.title}``) } else { queue.metadata.channel.send(``Track **${track.title}** queued``); } });

player.events.on('audioTracksAdd', (queue, track) => { if (queue.node.isPlaying()){ queue.metadata.channel.send(``Playlist added ${track.title}``) } else { queue.metadata.channel.send(``Playlist starts from title: ${track.title}``); } });

samusaran commented 1 year ago

I did not realize that this was an issue until I saw messages in Zerio's Discord channel. The problem relates to audioTrackAdd and audioTracksAdd listeners. I have solved this by adding if condition to listeners:

player.events.on('audioTrackAdd', (queue, track) => { if (queue.node.isPlaying()){ queue.metadata.channel.send(Added to the queue ${track.title}) } else { queue.metadata.channel.send(Track ${track.title} queued); } });

player.events.on('audioTracksAdd', (queue, track) => { if (queue.node.isPlaying()){ queue.metadata.channel.send(Playlist added ${track.title}) } else { queue.metadata.channel.send(Playlist starts from title: ${track.title}); } });

I didn't tried this fix, but how that would help?

tuomonen commented 1 year ago

I did not realize that this was an issue until I saw messages in Zerio's Discord channel. The problem relates to audioTrackAdd and audioTracksAdd listeners. I have solved this by adding if condition to listeners: player.events.on('audioTrackAdd', (queue, track) => { if (queue.node.isPlaying()){ queue.metadata.channel.send(Added to the queue ${track.title}) } else { queue.metadata.channel.send(Track ${track.title} queued); } }); player.events.on('audioTracksAdd', (queue, track) => { if (queue.node.isPlaying()){ queue.metadata.channel.send(Playlist added ${track.title}) } else { queue.metadata.channel.send(Playlist starts from title: ${track.title}); } });

I didn't tried this fix, but how that would help?

When a player starts to play, it checks the queue and notifies that it is empty, and skips to emptyQueue event. If you remove those audioTrack(s)Add events, the code works fine. So, the solution actually uses the event path: connection -> playerStart -> audioTrackAdd/audioTracksAdd -> emptyQueue. My solution forces the event path to if condition. That it doesn't reach emptyQueue while it is playing.

samusaran commented 1 year ago

So since this code only writes messages, if i remove the event handler altogether, the issue gets solved anyway?

Also I don't get how this fix should be platform dependent (not needed on windows, but needed on linux)

febkosq8 commented 1 year ago

When a player starts to play, it checks the queue and notifies that it is empty, and skips to emptyQueue event. If you remove those audioTrack(s)Add events, the code works fine. So, the solution actually uses the event path: connection -> playerStart -> audioTrackAdd/audioTracksAdd -> emptyQueue. My solution forces the event path to if condition. That it doesn't reach emptyQueue while it is playing.

I tested out that suggestion, as expected doesn't help. Also I am sure that the playerEvents don't work that way.

tscheick commented 1 year ago

I recently moved my bot to a Digital Ocean droplet using Ubuntu 22.04 and I'm getting the same debug log as OP.

I set up a remote debugger and found it's breaking in the 'youtube-sr' package due to a rejected promise when trying to fetch.

youtube-sr/dist/mod.js line 532 inside getHTML.

Exception has occurred: TypeError [ERR_INVALID_STATE]: Invalid state: Writer has been released at new NodeError (node:internal/errors:399:5) at lazyWritableReleasedError (node:internal/webstreams/writablestream:95:19) at writableStreamDefaultWriterRelease (node:internal/webstreams/writablestream:1004:30) at finalize (node:internal/webstreams/readablestream:1289:5) at node:internal/webstreams/readablestream:1322:15 at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

I'm not sure where to go with this though. Is this useful?

Edit: I just noticed @skdhg is the owner of the 'youtube-sr' package and he marked this thread as "under discussion". Just wanted to ping him so he see's this.

Edit 2: Sorry all, I think this was a red herring. 'youtube-sr' will try to use a global fetch if it exists and node v18+ has a built in global.fetch which was causing this "uncaught exception" in the debugger. So, as a test, in my code I deleted global.fetch before trying to play music which caused 'youtube-sr' to use node-fetch instead but it's still not playing music. I'm just not getting a break point now. My debug log still looks the same as OP.

Debug emitted: state change: from {"status":"buffering","resource":true,"stepTimeout":false} to {"status":"playing","missedFrames":0,"playbackDuration":0,"resource":true,"stepTimeout":false} Debug emitted: [NW] [WS] >> {"op":5,"d":{"speaking":1,"delay":0,"ssrc":395145}} Debug emitted: [NW] [WS] >> {"op":5,"d":{"speaking":0,"delay":0,"ssrc":395145}} Debug emitted: Track {"title":"JAY-Z - Anything","isTransitionMode":false} was marked as finished Debug emitted: Adding track to history and emitting finish event since transition mode is disabled... Debug emitted: No more tracks left in the queue to play and repeat mode is off, initiating #emitEnd() Debug emitted: state change: from {"status":"playing","missedFrames":0,"playbackDuration":120,"resource":true,"stepTimeout":false} to {"status":"idle","resource":false,"stepTimeout":false}

The status changes to playing and then is marked as finished with a playback duration of 120 ms. Back to the drawing board...

twlite commented 1 year ago

if it was youtube-sr problem, it would not return search result in first place. The issue occurs at audio player, where stream just ends after 120ms playback. This could possibly be ffmpeg issue? I don't have time to look into it at the moment as im busy these days.

AaronDJ-Dev commented 1 year ago

I'm also going to do some testing this week. I agree with skdhg on this one. It's very possible it's a ffmpeg issue due to it having issues with the stream data. I'll update this thread if I discover anything valuable for sharing.

tuomonen commented 1 year ago

Sorry, I been also buzy. I have a student group as trainers and we have developed a discord bot for taking a break and it based on a music bot. One of students uses Linux and last week a fix I mentioned earlier did worked but not on this week. Another thing what I noticed yesterday (Windows user) was that one of the students had removed queue from play.js and they is still able to add /play music1, /play music2, /play music3, etc. (as there would be a queue) and player plays music2 after it has finished music1. Earlier at list in @discord/voice and distube adding a new /play music command caused (without queue handling) that player switches to a new song which just added.

We have used singleton and useMasterPlayer() in our project and code based on strictly discord-player 6.0, discord v.14, and node.js 18.15.

twlite commented 1 year ago

I will try to investigate this issue today and let you guys know 👍

twlite commented 1 year ago

Conclusion

The problem seems to be static binaries of ffmpeg, pulled from johnvansickle.com/ffmpeg. Please install ffmpeg via apt or other package managers and avoid static binaries.


Update 1:

The bot seems to be working fine on WSL - Ubuntu 22.04 under following circumstances:

Update 2 (follow-up to update 1):

This issue occurs upon using ffmpeg-static instead of the version used in update 1:

FFmpeg Static

ffmpeg version 5.0.1-static https://johnvansickle.com/ffmpeg/

Debug Log

[DEBUG] Player triggered for Track {"title":"2 Phút Hơn - KAIZ Remix","reason":"normal"}

[DEBUG] state change:
from {"status":"buffering","resource":true,"stepTimeout":false}
to {"status":"playing","missedFrames":0,"playbackDuration":0,"resource":true,"stepTimeout":false}

[DEBUG] [NW] [WS] >> {"op":5,"d":{"speaking":1,"delay":0,"ssrc":746032}}

[DEBUG] [NW] [WS] >> {"op":5,"d":{"speaking":0,"delay":0,"ssrc":746032}}

[DEBUG] Track {"title":"2 Phút Hơn - KAIZ Remix","isTransitionMode":false} was marked as finished

[DEBUG] Adding track to history and emitting finish event since transition mode is disabled...

[DEBUG] No more tracks left in the queue to play and repeat mode is off, initiating #emitEnd()

[DEBUG] state change:
from {"status":"playing","missedFrames":0,"playbackDuration":120,"resource":true,"stepTimeout":false}
to {"status":"idle","resource":false,"stepTimeout":false}

Update 3 (heroku buildpack ffmpeg latest)

This buildpack seems to be using johnvansickle.com/ffmpeg (the same one is used by ffmpeg-static package) based on this line https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest/blob/25e435c249349b5d201f346449fcdf26bce1a065/bin/compile#L34

The problem seems to be static binaries of ffmpeg, pulled from johnvansickle.com/ffmpeg. Please install ffmpeg via apt or other package managers and avoid static binaries.

tscheick commented 1 year ago

This fixes my issue. Thanks for taking the time to look!

I removed 'ffmpeg-static' from my project yesterday but didn't realize it was still in my node_modules folder (I don't do much js dev). Once I cleared it out, it started to work. I can also confirm it works with ffmpeg 6.0 but I can't recommend anyone install it since it may break something else for you.

twlite commented 1 year ago

Removed ffmpeg and ffmpeg-static and installed ffmpeg through sudo apt install ffmpeg and cleared npm cache as well and then tried still track ending immediately.

Ubuntu 22.10 btw

What is the ffmpeg version as per player.scanDeps()?

CaptSpider4 commented 1 year ago

Nvm i completely removed bot files, hosted again and it worked I guess even after npm cache clean --force cache was not cleared for some reason

samusaran commented 1 year ago

Solved on centos by removing ffmpeg-static, removing package-lock.json and reinstalled all packages. Ffmpeg installed on system is version 5.x

twlite commented 1 year ago

from discord-player v6.3x, the package ships with its own ffmpeg implementation which gives less priority to static binaries so it should work better than how it used to. You can also set FFMPEG_PATH environment variable to load ffmpeg from custom path if needed.

Loadren commented 1 year ago

I'm sorry, I've done everything here without it working.

My buildbacks are as follow :

  1. https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest.git
  2. https://github.com/xrisk/heroku-opus.git
  3. heroku/nodejs

Here is the interesting part of my package.json

{
    "engines": {
        "node": "18.14.2",
        "npm": "9.6.7"
    },
    "dependencies": {
        "@discord-player/extractor": "^4.4.0",
        "@discordjs/opus": "^0.8.0",
        "discord-player": "^6.6.1",
        "discord.js": "^14.11.0",
        "ms": "^3.0.0-canary.1",
        "play-dl": "^1.9.6"
    }
}

I tried npm install then I tried yarn, both before and after removing lock files and node_modules folder. I tried reseting the Heroku repo by cleaning everything inside and reinstalling from scratch.

I don't think I can sudo snap install ffmpeg inside of Heroku since first, it's bash, and I don't think I have the rights to do so. Any advice?

twlite commented 1 year ago

@Loadren can you try running your bot inside docker container? Pretty sure heroku supports docker

Loadren commented 1 year ago

@skdhg I've never used Docker, but I'll try it and give you feedback.

Loadren commented 1 year ago

@skdhg Docker worked! Thanks!

Klairm commented 4 months ago

Im having this same problem, i already tried using docker images but nothing, tried 19.7.0-bullseye-slim , 20, 16, and it doesnt work, also it wont work on my main machine which is debian 12.

Any ideas?

Stream extraction was successful for Track { title: Como Camarón, url: https://open.spotify.com/track/1VB4sadHjFcFklHcZuoROi } (Extractor: com.discord-player.spotifyextractor) Waiting for willPlayTrack event to resolve... skipFFmpeg is set to true and stream is demuxable, creating stream with type pcm Preparing final stream config: { "dispatcherConfig": { "disableBiquad": false, "disableEqualizer": false, "disableVolume": false, "disableFilters": false, "disableResampler": true, "sampleRate": 48000, "eq": [], "defaultFilters": [], "volume": 100, "data": { "id": "1259464874015068161", "title": "Como Camarón", "description": "Como Camarón by Estopa", "author": "Estopa", "url": "https://open.spotify.com/track/1VB4sadHjFcFklHcZuoROi", "thumbnail": "https://i.scdn.co/image/ab67616d0000b2731a311570340a4f6530da158b", "duration": "03:22", "durationMS": 202000, "views": 0, "requestedBy": null, "playlist": null }, "type": "raw", "skipFFmpeg": true }, "playerConfig": { "queue": false, "transitionMode": false, "seek": 0 } } Initiating DSP filters pipeline... Executing onAfterCreateStream hook... Preparing AudioResource... Initializing audio player... state change: from {"status":"idle","resource":false,"stepTimeout":false} to {"status":"buffering","resource":true,"stepTimeout":false} Dispatching audio... Player triggered for Track {"title":"Como Camarón","reason":"normal"} state change: from {"status":"buffering","resource":true,"stepTimeout":false} to {"status":"playing","missedFrames":0,"playbackDuration":0,"resource":true,"stepTimeout":false} [NW] [WS] >> {"op":5,"d":{"speaking":1,"delay":0,"ssrc":821694}} [NW] [WS] >> {"op":5,"d":{"speaking":0,"delay":0,"ssrc":821694}} Track {"title":"Como Camarón","isTransitionMode":false} was marked as finished Adding track to history and emitting finish event since transition mode is disabled... No more tracks left in the queue to play and repeat mode is off, initiating #emitEnd() state change: from {"status":"playing","missedFrames":0,"playbackDuration":120,"resource":true,"stepTimeout":false} to {"status":"idle","resource":false,"stepTimeout":false}

Mylloon commented 4 months ago

I personally use node:22.2.0-bullseye-slim

Loadren commented 4 months ago

@Klairm Here is my current Dockerfile

FROM node:18.14.2-alpine

WORKDIR /usr/src/app

COPY package*.json ./

RUN apk add --no-cache make gcc g++ python3 && \
    npm install && \
    apk del make gcc g++ python3

RUN apk add --no-cache ffmpeg

COPY . .

CMD ["node", "./index.js"]

Try using @distube/ytdl-core if you use YouTube. Sometimes, you may have to switch to a different library (like play-dl) to fix this problem.

Klairm commented 4 months ago

@Klairm Here is my current Dockerfile

FROM node:18.14.2-alpine

WORKDIR /usr/src/app

COPY package*.json ./

RUN apk add --no-cache make gcc g++ python3 && \
    npm install && \
    apk del make gcc g++ python3

RUN apk add --no-cache ffmpeg

COPY . .

CMD ["node", "./index.js"]

Try using @distube/ytdl-core if you use YouTube. Sometimes, you may have to switch to a different library (like play-dl) to fix this problem.

After moving to ytdl-core the issue was fixed, thanks

febkosq8 commented 4 months ago

Im having this same problem, i already tried using docker images but nothing, tried 19.7.0-bullseye-slim , 20, 16, and it doesnt work, also it wont work on my main machine which is debian 12.

Any ideas?

Sounds like your most likely problem is with the streaming library. Go one by one through the packages mentioned in https://discord-player.js.org/guide/welcome/welcome

$ npm install --save youtube-ext
# or
$ npm install --save play-dl
# or
$ npm install --save @distube/ytdl-core
# or
$ npm install --save yt-stream
# or
$ npm install --save ytdl-core

If this solves your problem, then keep note than that particular library might stop working one day and you might have to go thro the list again from top. Chances are you will find something that works.

retrouser955 commented 4 months ago

Adding @febkosq8 statement, it is also recommended to keep your YouTube libraries to the latest as YouTube regularly updates their applications.