umutxyp / MusicBot

An enhanced music bot that is compatible with discord.js v14 and works with slash commands. Discord music bot codes that can be used on any server and are simple to install.
https://discord.gg/codes
976 stars 1.07k forks source link

SUCCESS: Bot stops playing after around 1 minute #97

Open Henrik-Henkel opened 1 year ago

Henrik-Henkel commented 1 year ago

The bot stops playing after around 1 minute of playback... No error in the console.

Any idea what could be causing this?

y0zhyck commented 1 year ago

I have the same thing going on

y0zhyck commented 1 year ago

How to Fix?

Henrik-Henkel commented 1 year ago

Discord has made an announcement on the Discord Developers server in regards to the change that broke most musicbots.

image

Henrik-Henkel commented 1 year ago

Whoops. Didn't mean to close the issue... Can we get an update for the bot?

y0zhyck commented 1 year ago

Discord has made an announcement on the Discord Developers server in regards to the change that broke most musicbots.

image

Okay, that's all, but how to fix the situation or wait for the expected fifteen years?

Henrik-Henkel commented 1 year ago

I think only the author can provide us with a fix for that

MiniGrief commented 1 year ago

Modified from this: https://github.com/discordjs/discord.js/issues/9185#issuecomment-1452514375

This is an issue inside of discord.js related to the screenshot above. You can add a patch to distube (a node module used in this bot) which seems to fix the issue.

MusicBot/node_modules/distube/dist/index.js Above this around line 754 this.connection.on(import_voice.VoiceConnectionStatus.Disconnected, (_, newState) => { Add this: this.connection.on('stateChange', (oldState, newState) => { const oldNetworking = Reflect.get(oldState, 'networking'); const newNetworking = Reflect.get(newState, 'networking'); const networkStateChangeHandler = (oldNetworkState, newNetworkState) => { const newUdp = Reflect.get(newNetworkState, 'udp'); clearInterval(newUdp?.keepAliveInterval); } oldNetworking?.off('stateChange', networkStateChangeHandler); newNetworking?.on('stateChange', networkStateChangeHandler); });

y0zhyck commented 1 year ago

like this? image

MiniGrief commented 1 year ago

like this? image

Above that, not below.

y0zhyck commented 1 year ago

like this? image

Above that, not below.

It worked, wow!!!!!

MadTiago commented 1 year ago

Modified from this: discordjs/discord.js#9185 (comment)

This is an issue inside of discord.js related to the screenshot above. You can add a patch to distube (a node module used in this bot) which seems to fix the issue.

MusicBot/node_modules/distube/dist/index.js Above this around line 754 this.connection.on(import_voice.VoiceConnectionStatus.Disconnected, (_, newState) => { Add this: this.connection.on('stateChange', (oldState, newState) => { const oldNetworking = Reflect.get(oldState, 'networking'); const newNetworking = Reflect.get(newState, 'networking'); const networkStateChangeHandler = (oldNetworkState, newNetworkState) => { const newUdp = Reflect.get(newNetworkState, 'udp'); clearInterval(newUdp?.keepAliveInterval); } oldNetworking?.off('stateChange', networkStateChangeHandler); newNetworking?.on('stateChange', networkStateChangeHandler); });

That comment has been updated according to https://github.com/discordjs/discord.js/issues/9185#issuecomment-1459083216 So in this case, you should use:

const networkStateChangeHandler = (oldNetworkState, newNetworkState) => {
    const newUdp = Reflect.get(newNetworkState, 'udp');
    clearInterval(newUdp?.keepAliveInterval);
}
this.connection.on('stateChange', (oldState, newState) => {
    Reflect.get(oldState, 'networking')?.off('stateChange', networkStateChangeHandler);
    Reflect.get(newState, 'networking')?.on('stateChange', networkStateChangeHandler);
});
Ren0X1 commented 1 year ago

any update?

MiniGrief commented 1 year ago

any update?

I think the issue in discordjs is actually fixed now so you can just update it using npm i @discordjs/voice@latest and it should work.

Hoshimikan6490 commented 1 year ago

Modified from this: discordjs/discord.js#9185 (comment)

This is an issue inside of discord.js related to the screenshot above. You can add a patch to distube (a node module used in this bot) which seems to fix the issue.

MusicBot/node_modules/distube/dist/index.js Above this around line 754 this.connection.on(import_voice.VoiceConnectionStatus.Disconnected, (_, newState) => { Add this: this.connection.on('stateChange', (oldState, newState) => { const oldNetworking = Reflect.get(oldState, 'networking'); const newNetworking = Reflect.get(newState, 'networking'); const networkStateChangeHandler = (oldNetworkState, newNetworkState) => { const newUdp = Reflect.get(newNetworkState, 'udp'); clearInterval(newUdp?.keepAliveInterval); } oldNetworking?.off('stateChange', networkStateChangeHandler); newNetworking?.on('stateChange', networkStateChangeHandler); });

I changed code like this and used npm i @discordjs/voice@latest. However, I saw this issue again. What I should do?

Hoshimikan6490 commented 1 year ago

I was fixed this problem. I seted like this.

client.config = config;
client.player = new DisTube(client, {
  leaveOnStop: config.opt.voiceConfig.leaveOnStop,
  leaveOnFinish: config.opt.voiceConfig.leaveOnFinish,
  leaveOnEmpty: config.opt.voiceConfig.leaveOnEmpty.status,
  emitNewSongOnly: true,
  emitAddSongWhenCreatingQueue: false,
  emitAddListWhenCreatingQueue: false,
  plugins: [
    new SpotifyPlugin(),
    new SoundCloudPlugin(),
    new YtDlpPlugin(),
    new DeezerPlugin(),
  ],
});

However, this change is for my program. So, it may not be a good change for programs in this repository.

Saadalayed commented 1 year ago

How do I fix it ?

Screenshot 2023-06-11 211355

Hoshimikan6490 commented 1 year ago

After running npm i, run node index.js. Does that fix it?

harshitkamboj commented 1 year ago

run this command

npm i @discordjs/voice@latest

Lucfost commented 1 year ago

thx it worked