discordjs / voice

Implementation of the Discord Voice API for discord.js and other JS/TS libraries
Apache License 2.0
328 stars 112 forks source link

AudioPlayer throws AudioPlayerError randomly after some time playing. #202

Closed hetrodoo closed 2 years ago

hetrodoo commented 2 years ago

Please describe the problem you are having in as much detail as possible:

Recently, I updated my music bot from discord js v12.5.3 to v13.1.0 and since then I've been experiencing the error AudioPlayerError being thrown after some time playing.

[AudioService/joinChannel (player)]:  AudioPlayerError: aborted
    at connResetException (node:internal/errors:691:14)
    at TLSSocket.socketCloseListener (node:_http_client:407:19)
    at TLSSocket.emit (node:events:406:35)
    at node:net:672:12
    at TCP.done (node:_tls_wrap:580:7) {
  resource: AudioResource {
    playbackDuration: 30560,
    started: true,
    silenceRemaining: -1,
    edges: [ [Object] ],
    playStream: WebmDemuxer {
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 5,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: true,
      _remainder: null,
      _length: 540672,
      _count: 540508,
      _skipUntil: null,
      _track: [Object],
      _incompleteTrack: {},
      _ebmlFound: true,
      [Symbol(kCapture)]: false,
      [Symbol(kCallback)]: [Function: bound onwrite]
    },
    metadata: null,
    silencePaddingFrames: 5,
    audioPlayer: AudioPlayer {
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      subscribers: [Array],
      _state: [Object],
      behaviors: [Object],
      debug: [Function (anonymous)],
      [Symbol(kCapture)]: false
    }
  }
}

Include a reproducible code sample here, if possible:

    private async joinChannel(guildId: string, channelId: string): Promise<{ player: AudioPlayer, connection: VoiceConnection }> {
        const {voiceAdapterCreator: adapterCreator} = await this._client.guilds.fetch(guildId);

        const connection = joinVoiceChannel({
            channelId,
            guildId,
            adapterCreator,
        });

        const player = createAudioPlayer();
        connection.subscribe(player);

        connection.on("stateChange", (_, newState) => {
            if (newState.status === VoiceConnectionStatus.Disconnected) {
                if (newState.reason === VoiceConnectionDisconnectReason.WebSocketClose && newState.closeCode !== 4014) {
                    connection.rejoin();
                }
            } else if (newState.status === VoiceConnectionStatus.Destroyed) {
                this.stop().catch((e) => console.error("[AudioService/joinChannel (connection/stateChange)]: ", e.toString()));
            }
        });
        connection.on("error", (error: Error) => {
            console.error("[AudioService/joinChannel (connection)]: ", error.message);
            this.stop().catch((e) => console.error("[AudioService/joinChannel (connection/error)]: ", e.toString()));
        });

        player.on("stateChange", (_, newState) => {
            (async () => {
                if (newState.status === AudioPlayerStatus.Idle) {
                    if (this._queue.length === 0) {
                        await this.stop();
                    } else {
                        await this.prepareAndPlay();
                    }
                }
            })().catch(e => console.error("[AudioService/joinChannel (player/stateChange)]: ", e.toString()));
        });
        player.on("error", async (error: Error) => {
            console.error("[AudioService/joinChannel (player)]: ", error);
            this.stop().catch((e) => console.error("[AudioService/joinChannel (player/error)]: ", e.toString()));
        });

        return {
            player,
            connection
        };
    }

Further details: Tested on 3 environments.

Windows Machine

Raspberry pi 3

GCP VM (Not as frequently as the others)

Relevant client options:

iim-ayush commented 2 years ago
[AudioService/joinChannel (player)]:  AudioPlayerError: aborted

This is a ytdl-core issue. Nothing discordjs/voice can do.

Anyone close this issue with external fault