0
votes

I'm new to Discord.js and I'm trying to have the bot join a voice channel and play an audio file on my computer. I have been following this guide: https://discord.js.org/#/docs/main/stable/topics/voice . Here is the Index.js page:

Colesbot.on('message', message=>{
    if (message.content === '/join') {
        // Only try to join the sender's voice channel if they are in one themselves
        if (message.member.voiceChannel) {
            message.member.voiceChannel.join().then(connection => {
                message.reply('I have successfully connected to the channel!');

                // To play a file, we need to give an absolute path to it
                const dispatcher = connection.playFile('C:\Users\bobal\Documents\GitHub\Spotify-Playlist-Discord-bot\Assets\Glory.mp3');

                dispatcher.on('end', () => {
                    // The song has finished
                    console.log('Finished playing!');
                  });

                dispatcher.on('error', e => {
                    // Catch any errors that may arise
                    console.log(e);
                  });

                  dispatcher.setVolume(0.5); // Set the volume to 50%
            }).catch(console.log);
    } else {
        message.reply('You need to join a voice channel first!');
      }
    }
 });
exports.run = (client, message, args) => {
    let user = message.mentions.users.first || message.author;
}

FFMPEG is installed and I have set the environment path for it. When I type FFMPEG in the command line I get the proper response.

Some have said I need to install the ffmpeg binaries but when I run npm install ffmpeg-binaries I get an error message that is here

So then I tried installing an older version and I'm now using [email protected] but when I type /join I get the error

[ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string. Received type object
1
... yes playing music with a discord bot is a pain ... I made one to play from youtube, it works half the time and for specific urls ... sorry I can't help much, maybe you can check my code github.com/gui3/discord-sandbot/blob/master/commands/play.jsgui3
did you install ffmpeg binaries on the bot server ?gui3
I remember that thing was a pain github.com/discordjs/discord.js/issues/…gui3
I have ffmpeg installed on my PC correctly, but when I try to run this command in my project folder: npm install ffmpeg-binaries I get a huge error message. Do you want me to post the error message in my question?Cole Perry

1 Answers

1
votes

Firstly you need to reset your token, you should never post it online as others can use it to access and control your bot

here is a good answer to your question

I think that you need to install FFMPEG and have the environment path set for it, however, can you provide more information, console logs, behaviour etc