Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Voice receiver stream error #8778

Open
int0x80-sys opened this issue Oct 22, 2022 · 2 comments · May be fixed by #10455
Open

Voice receiver stream error #8778

int0x80-sys opened this issue Oct 22, 2022 · 2 comments · May be fixed by #10455

Comments

@int0x80-sys
Copy link

int0x80-sys commented Oct 22, 2022

Which package is this bug report for?

voice

Issue description

When i susbcribe to the receiver, and add an event listener to the "finish" event of the opusStream, the bot crashes with the follow:

node:events:491
      throw er; // Unhandled 'error' event
      ^

Error [ERR_STREAM_PUSH_AFTER_EOF]: stream.push() after EOF
    at new NodeError (node:internal/errors:387:5)
    at readableAddChunk (node:internal/streams/readable:277:30)
    at AudioReceiveStream.Readable.push (node:internal/streams/readable:228:10)
    at AudioReceiveStream.push (file:///app/node_modules/@discordjs/voice/dist/index.mjs:1102:18)
    at VoiceReceiver.onUdpMessage (file:///app/node_modules/@discordjs/voice/dist/index.mjs:1267:16)
    at VoiceUDPSocket.emit (node:events:513:28)
    at VoiceUDPSocket.onMessage (file:///app/node_modules/@discordjs/voice/dist/index.mjs:265:10)
    at Socket.<anonymous> (file:///app/node_modules/@discordjs/voice/dist/index.mjs:247:48)
    at Socket.emit (node:events:513:28)
    at UDP.onMessage [as onmessage] (node:dgram:922:8)
Emitted 'error' event on AudioReceiveStream instance at:
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'ERR_STREAM_PUSH_AFTER_EOF'
}

Code sample

import { token } from "./config";

import { Client, GatewayIntentBits } from "discord.js";
import {
    EndBehaviorType,
    getVoiceConnection,
    joinVoiceChannel,
    VoiceConnectionStatus
} from "@discordjs/voice";

export const bot = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.MessageContent,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.GuildVoiceStates
    ]
});

bot.on("messageCreate", (msg) => {
    const { guild, member } = msg;
    if(!guild || !member?.voice.channelId)
        return;

    const channelId = member.voice.channelId;

    if(msg.content !== "?join")
        return;

    let voiceConnection = getVoiceConnection(guild.id);
    if(voiceConnection)
        return;

    voiceConnection = joinVoiceChannel({
        channelId,
        guildId: guild.id,
        adapterCreator: guild.voiceAdapterCreator,
        selfDeaf: false
    });

    if(!voiceConnection)
        return;

    voiceConnection.once(VoiceConnectionStatus.Disconnected, () => voiceConnection?.destroy());

    const { receiver } = voiceConnection;
    receiver.speaking.on("start", async (userId) => {
        const opusStream = receiver.subscribe(userId, {
            end: {
                behavior: EndBehaviorType.AfterSilence,
                duration: 100
            }
        });

        opusStream.on("finish", () => console.log("End"));
    });
});

bot.once("ready", () => console.log("Bot Ready..."));

bot.login(token);

Package version

@discordjs/[email protected]

Node.js version

v16.17.1

Operating system

Ubuntu 20.04

Priority this issue should have

Low (slightly annoying)

Which partials do you have configured?

Not applicable (subpackage bug)

Which gateway intents are you subscribing to?

Guilds, GuildVoiceStates, GuildMessages, MessageContent

I have tested this issue on a development release

No response

@Asertus1
Copy link

Asertus1 commented Mar 7, 2023

@discordjs/[email protected] and node v19.6.1, still got the error.

Error [ERR_STREAM_PUSH_AFTER_EOF]: stream.push() after EOF
    at new NodeError (node:internal/errors:399:5)
    at readableAddChunk (node:internal/streams/readable:285:30)
    at Readable.push (node:internal/streams/readable:234:10)
    at AudioReceiveStream.push (C:\Users\Maxime\Documents\Programmation\_temp\DiscordGPT\node_modules\@discordjs\voice\dist\index.js:1069:18)
    at VoiceReceiver.onUdpMessage (C:\Users\Maxime\Documents\Programmation\_temp\DiscordGPT\node_modules\@discordjs\voice\dist\index.js:1242:16)
    at VoiceUDPSocket.emit (node:events:512:28)
    at VoiceUDPSocket.onMessage (C:\Users\Maxime\Documents\Programmation\_temp\DiscordGPT\node_modules\@discordjs\voice\dist\index.js:293:10)
    at Socket.<anonymous> (C:\Users\Maxime\Documents\Programmation\_temp\DiscordGPT\node_modules\@discordjs\voice\dist\index.js:275:48)
    at Socket.emit (node:events:512:28)
    at UDP.onMessage [as onmessage] (node:dgram:933:8)
Emitted 'error' event on AudioReceiveStream instance at:
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  code: 'ERR_STREAM_PUSH_AFTER_EOF'
}

Could someone take a look at this please ? I don't think it is hard to fix, but I don't have enough knowledge to do it. I am sorry if I am wrong.

@nyapat nyapat linked a pull request Aug 22, 2024 that will close this issue
@nyapat
Copy link
Contributor

nyapat commented Aug 22, 2024

Looks like it's related to the subscribing to the user, not listening to 'finish' (this doesn't exist on Readable btw, it's "end") or destroying the connection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants