discordjs / discord.js

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

[Linux only] AudioPlayer keeps setting itself to status: 'autopaused' #8993

Open rhighs opened 1 year ago

rhighs commented 1 year ago

Which package is this bug report for?

voice

Issue description

How to reproduce:

  1. Get a valid audio resource
  2. Get a connection to a voice channel
  3. Play the audio resource

Result: the bot won't start playing any audio, instead debugging the audio player state you'll see it set to autopaused.

Documentation states: AutoPaused - the state a voice connection will enter when the player has paused itself because there are no active voice connections to play to. though, it's not the case as you'll see from the code below.

However, this has only happened running under arch linux, running on windows gives no issue whatsoever. I thought of a possible compatibility error in the opus bindings, so I tried switching from discordjs/opus to opusscript. Unfortunately it didn't solve the issue.

Code sample

async function playSong(resourceUrl: string, audioPlayer: AudioPlayer): Promise<AudioPlayer> {
    const resource = createAudioResource(resourceUrl, {
        inputType: StreamType.Arbitrary,
    });

    audioPlayer.play(resource);
    return entersState(audioPlayer, AudioPlayerStatus.Playing, 5e3);
}

async function playAudioInVoiceChannel(stream: string | Blob | Int32Array,
    voiceChannel: VoiceChannel,
    voiceAdapterCreator: InternalDiscordGatewayAdapterCreator,
    audioPlayer : AudioPlayer | null = null
): Promise<[AudioPlayer, VoiceConnection | null]> {
    if (!audioPlayer) {
        audioPlayer = createAudioPlayer();
    }

    audioPlayer = await playSong(stream as string, audioPlayer);
    let connection = await channelConnection(voiceChannel, voiceAdapterCreator);
    let _subscription = connection.subscribe(audioPlayer);
    return [audioPlayer, connection];
}

Package version

14.6

Node.js version

16.18

Operating system

Arch Linux x86_64

Priority this issue should have

Low (slightly annoying)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

Guilds, GuildVoiceStates, GuildMessages

I have tested this issue on a development release

No response

Greensky-gs commented 1 year ago

The same happens to me (windows 11 and Linux 5.15.0-25 for VPS) sometimes. I can't figure what causes the issues, but according to the documentation, it is caused by no valid subscription for the player

kudryavka310 commented 1 year ago

Node Version : 16.18.0

I am facing the same problem myself. I was trying to eliminate the AutoStop process itself. @discordjs/voice/dist/index.js:line 996 I tried comment out the relevant process in AutoStop is no longer triggered, but the sound is not played. The same symptom occurs in the end.

Sorry if this is hard to read, I've translated the text. image

bituuu commented 1 year ago

Same happens to me (discord js version is 13.6.0 and node version is 17.6.0) the songs plays for ~30 seconds and then the state changes in autopaused

okdargy commented 1 year ago

Having the same issue, can't play single second of audio without it going into autopaused. The VoiceConnectionStatus.Ready listener is never fired so I wonder if that has to do with this problem.

image

M1000fr commented 5 months ago

Did u add GuildVoiceStates Intents like

const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMembers,
        GatewayIntentBits.GuildVoiceStates,
    ],
});