2023-02-26

Discord.js Voice Not Playing Audio While AudioPlayerStatus is Playing

I can't seem to figure out why my bot isn't playing audio. I have installed all the necessary dependencies and below is the dependency log and code. Incase it was the audio files, I tried different paths and youtube links and nothing seems to be working.

The block of code is confirmed getting ran since console logs but no audio comes through. Bot joins vc with no issue.

Core Dependencies
- @discordjs/voice: 0.14.0
- prism-media: 1.3.4

Opus Libraries
- @discordjs/opus: 0.8.0
- opusscript: 0.0.8

Encryption Libraries
- sodium-native: 4.0.1
- libsodium-wrappers: 0.7.11
- tweetnacl: not found

FFmpeg
- version: 5.0.1-essentials_build-www.gyan.dev
- libopus: yes

voiceStateUpdate.js event file below

const { Events } = require('discord.js');
const { joinVoiceChannel, AudioPlayerStatus } = require('@discordjs/voice');




module.exports = {
    name: Events.VoiceStateUpdate,
    async execute(oldState, newState) {

        //Check if muting / unmuting
        //Check if deafening / undeafening
        //Check if channel Id is null i.e. if I'm leaving not arriving
        if (newState.selfMute == oldState.selfMute && newState.selfDeaf == oldState.selfDeaf && newState.channelId != null && newState.member.user.id == '188765194246291468'){
            console.log("Syan has entered");

            const fs = require('node:fs');
            const path = require('node:path');

            const seinPath = path.join(__dirname, '../seinfeld_bites');
            const seinFiles = fs.readdirSync(seinPath).filter(file => file.endsWith('.mp3'));

            const { createAudioResource } = require('@discordjs/voice');

            //const { generateDependencyReport } = require('@discordjs/voice');

            const connection = joinVoiceChannel({
                channelId: newState.channelId,
                guildId: newState.guild.id,
                adapterCreator: newState.guild.voiceAdapterCreator,
            });

            const { createAudioPlayer } = require('@discordjs/voice');

            const player = createAudioPlayer();

            const resource = createAudioResource(seinFiles[1]);
            player.play(resource);
            connection.subscribe(player);

            player.on(AudioPlayerStatus.Playing, () => {
                console.log('Playing');
            })

            //console.log(generateDependencyReport());

            //console.log(connection);
        }

    },
};

I've gone over all the dependencies, tried different audio resources and tried it on different servers. Any help would be fantastic. I have the GUILD_VOICE_STATES in my index.js and the bot is joining vc so I don't think it could be that.



No comments:

Post a Comment