Discord.js: 'end' event on dispatcher not triggered

Created on 30 May 2019  路  18Comments  路  Source: discordjs/discord.js

Music code stopped working without being changed. dispatcher.on("end") is never triggered.

lmk what other info you need

voice

Most helpful comment

If any more off-topic gets brought into this, I am just going to lock this issue and you'll have more luck opening a new one without needless discussions.

All 18 comments

all what that 'hypocrite' was saying, was to move out from support channel.
You can always appeal from the mute.

I just reviewed what happened in the support channel and it looks like you insulted someone unprovoked (attached) and then continued to act defensive over what happened - it's unfair to refer to our team as "power-tripping hypocrites" when we're just enforcing rules that facilitate a healthy environment in our support channels.

image

As for the actual voice issue, could you send the version of Discord.js you're using? If you're on v12 (master branch), you should be listening for the finish event instead of end

your mods insult people all the time. when i was active in your general channel, there was a very young member trying to learn to code that was often verbally abused by high ranking members and mods. There have been other cases whey're they've either condescending, insulting or otherwise toxic too. So yes, they are hypocrites. You should really actually pay attention to the server sometimes and you'd see for yourself how badly that place is run. It's objectively toxic.

Anyway. It's version 11.5.1

If any more off-topic gets brought into this, I am just going to lock this issue and you'll have more luck opening a new one without needless discussions.

@Addaaamm could I see the code you're using to play audio?

const startStream = (msg) => {
  dispatcher = connection.playStream(ytdl(queue[0], {filter: "audioonly"})).catch(console.log)
  ytdl.getInfo(queue[0]).then(info => msg.channel.send(`Now playing ${info.title}`));
  dispatcher.on("end", () => {
    if (!repeat) {
      queue.shift();
      djs.shift();
    }
    if (queue.length) return startStream(msg);
    connection.disconnect();
  })
}
// which is called by:
 play: async (msg) => {
    if (!msg.member.voiceChannel) return error(msg, "You need to be in a voice channel to use music commands");
    if (msg.channel.id !== "515323446117400576") return msg.channel.send("Use music commands in <#515323446117400576> please");
    let link = msg.content.split(" ")[1];
    if (!link) return error(msg, "Provide a youtube URL or search term!");
    if (!ytdl.validateURL(link)) link = await search(msg.fullarg);
    if (queue.includes(link)) return error(msg, "That song is already playing or in the queue!");
    queue.push(link);
    djs.push(msg.author.id);
    ytdl.getInfo(link).then(info => msg.channel.send(`Added ${info.title} to the queue`));
    if (!msg.guild.voiceConnection) {
      msg.member.voiceChannel.join().then((connect) => {
        connection = connect;
        return startStream(msg);
      })
    }
  }

idfk how to make a code box on this site lol, think that's readable enough

Could you also add dispatcher.on('error', console.error) so we can debug to see if there are any errors occurring that might prevent the dispatcher from ending properly

Done. Nothing was logged

Can you add the following:

client.on('debug', msg => {
  if (msg.includes('VOICE')) console.log(msg);
});

and send the output?

No output, assuming it was meant to log something as the end event fails to be triggered

Whoops, sorry I forgot you said 11.5.1, what I suggested wouldn't work. Can you try this instead:

voiceConnection.on('debug', console.log);
dispatcher.on('debug', console.log);

Node v13.8.0
discord.js 11.5-dev
ffmpeg 4.2.2

I mention the problem in https://github.com/discordjs/discord.js/issues/3362 when commenting.

When reading a stream created with fs from a file, if the file is too short, there's no audio, and the end / close events are not triggered until another audio is played, and the dispatcher.stream.bytesRead is equal to 0

const stream = fs.createReadStream(filename);
const dispatcher = connection.playStream(stream);
stream.on("close", end => {
  console.log("stream closed");
  console.log('stream bytesRead', stream.bytesRead);
});
dispatcher.stream.on("end", end => {
  console.log("dispatcher stream ended");
  console.log('dispatcher stream bytesRead', dispatcher.stream.bytesRead);
});
dispatcher.stream.on("close", end => {
  console.log("dispatcher stream closed");
  console.log('dispatcher stream bytesRead', dispatcher.stream.bytesRead);
});
dispatcher.on("end", end => 
  console.log("ended");
  console.log('dispatcher bytesRead', dispatcher.stream.bytesRead);
  console.log('stream time', dispatcher.totalStreamTime);
});
file size 74062
stream closed
stream bytesRead 74062
ended
dispatcher bytesRead 0
stream time 700
dispatcher stream ended
dispatcher stream bytesRead 0
dispatcher stream closed
dispatcher stream bytesRead 0

3362

https://discord.js.org/#/docs/main/stable/class/StreamDispatcher

It doesn't look like "finish" event is not documented anywhere, while "end" was documented on the v11 docs. (https://discord.js.org/#/docs/main/v11/class/StreamDispatcher?scrollTo=e-end)

I believe that's because it's inherited from NodeJS's WritableStream#finish event.
https://nodejs.org/api/stream.html#stream_event_finish

the finish event is inhereted from WriteableStream
https://nodejs.org/api/stream.html#stream_event_finish

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LLamaFTL picture LLamaFTL  路  3Comments

xCuzImPro picture xCuzImPro  路  3Comments

iCrawl picture iCrawl  路  3Comments

Alipoodle picture Alipoodle  路  3Comments

DatMayo picture DatMayo  路  3Comments