ItzJR
ItzJR

Reputation: 1

Discord.js - Audio Resource not playing with no errors

The bot enters and acts like its talking / playing it but it isn't it also does not even give an error, the piece of code to run the file is as follows:

module.exports = {
    name: 'play',
    description: 'gets bots playing thing',
    execute(client, message, args, discord){
        // Make sure person who did command is in a voice channel
        const vc = message.member.voice.channel;
        if(!vc) return message.reply('You must be in a voice channel to play music!');

        // Join the voice channel
        vc.join();

        // Start Playing Audio
        const { createAudioPlayer, NoSubscriberBehavior } = require('@discordjs/voice');

        const player = createAudioPlayer({
            behaviors: {
                noSubscriber: NoSubscriberBehavior.Pause,
            },
        });

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

        const resource = createAudioResource('../audio/sound.mp3');

        player.play(resource);

        player.on('error', error => {
            console.error(`Error: ${error.message} with resource ${error.resource.metadata.title}`);
            player.play(getNextResource());
        });
    }
}

Upvotes: 0

Views: 1502

Answers (1)

Touché
Touché

Reputation: 574

There are a few things that could be causing your problem.

First of all, check if you have the GUILD_VOICE_STATES intent added to your client. Without this your bot will not be able to play audio and will exhibit the exact behavior you're describing.

If this was not the problem, however, the next best thing I would recommend is to make the path to your .mp3 file absolute using path.resolve. Sometimes having a relative path can create issues for your player.

Finally, a Discord.js/voice provides a good way to debug dependencies in the generateDependecyReport() function. Make sure to check if you have the most up-to-date versions of your libraries and if you have one of all types of libraries necessary for voice functions.

Upvotes: 1

Related Questions