discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.4k stars 3.97k forks source link

The function `dispatcher.pause()` and `dispatcher.resume()` only works on a second switch #5300

Closed SrRapero720 closed 3 years ago

SrRapero720 commented 3 years ago

When i stop a song with .pause() it stops (as it should), but when i use .resume() the song does not resume playing and does not do so by repeating the function one more time.

for the song to resume it must be "paused" again and then "resumed". the process is repeated in the same way once the song is resumed (don't gives me errors).

MORE DETAILS (AND TIMINGS): https://youtu.be/OsdpQEdE1QE

import Discord from 'discord.js';
import ytdl from 'ytdl-core';
import dotenv from 'dotenv';
import SrConsole from "sr-console";
import path from "path";

const __dirname = path.resolve('..')

const console = new SrConsole({
    dirname: __dirname,
    filter: [
        "[REDACTED]"
    ]
});

dotenv.config();

const client: Discord.Client = new Discord.Client();
const menu: Array<Discord.StreamDispatcher | undefined> = new Array();

client.on('ready', () => {
    console.log('the server is ready... bot started')
});

client.on('error', (dat) => console.err(dat));
client.on('warn', (dat) => console.warn(dat));
client.on('debug', (dat) => console.send(dat));

client.on('message', async (msg) => {
    if (msg.content === "--demo-play") {
        const voiceIP = await msg.member?.voice.channel?.join();
        menu.push(voiceIP?.play(ytdl('https://www.youtube.com/watch?v=GYtBoxGB6Wo')));
        console.debug('Music started to play');
    }

    if (msg.content === "--pause") {
        menu[0]?.pause();
        console.debug('Music Paused');
        console.debug('Paused status:', menu[0]?.paused);
    }

    if (msg.content === "--resume") {
        menu[0]?.resume();
        console.debug('Music resume');
        console.debug('Paused status:', menu[0]?.paused);
    }
});

client.login(process.env.TOKEN);

export default client; //unnecesary

Further details:

Relevant client options:

BocajBot commented 3 years ago

I had a similar issue. The issue was fixed after uninstalling node 15.8 and installing 14.15.4

GeorgeH005 commented 3 years ago

Same issue fixed by installing latest lts node 14.x

BearTS commented 3 years ago

Developers should fix it for node v15.x

JaxkDev commented 3 years ago

Having this exact issue on node v15.11.0 but the pause/resume x2 doesn't work as a 'hacky fix'

MrPropre commented 3 years ago

The "hacky fix" does not work when pausing the song with silent option.

- dispatcher.pause(true)
+ dispatcher.pause()
jbelford commented 3 years ago

I also found this happening for LTS v14.17.0

Fixed by using v14.16

Hazmi35 commented 3 years ago

Could reproduce with Node.js version 14.17.0 or above

slack2450 commented 3 years ago

Can confirm is occuring on v14.17.0 Downgrading to v14.16.1 resolved this for me

amishshah commented 3 years ago

Hi there,

We're working on a new implementation of Discord's Voice API that has better playback quality and is more reliable than what we currently support in Discord.js v12 - check it out at https://github.com/discordjs/voice!

The new library solves many of the issues that users are facing, and as part of this, we're dropping built-in support for voice in our next major release. We have a PR (https://github.com/discordjs/discord.js/pull/5402) that adds native support for our new voice library - once this PR is merged, this issue will be closed.

You can still use our new voice library before that PR lands - just take a look at our music bot example to see how to get started upgrading your voice code. By using the boilerplate music player in the example, you can make it even easier to upgrade your code.

Note that the PR above only reduces some of the boilerplate code you'd otherwise have to write - you do not have to wait for the PR to be merged to start using the new voice library.


If you have any questions about this, feel free to: