2
votes

I have a discord bot writte in discord js. I have one command that plays a mp3 file in a voice channel.

const connection = await channel.join();
const dispatcher = connection.playStream(fs.createReadStream('/absolute/path/to/file.mp3'), { type: 'ogg/opus', volume: true });

If i run the bot on my windows pc, everything works fine. The bot joins the channel, plays the file and leaves again. If i run the bot on my Ubuntu 18.04 VM though, the bot joins and immideatly disconnects without playing the file.

The path to the mp3 file is absolute. I have already tried using connection.playFile(path) instead with the same problem. I tried using opusscript and i tried using node-opus. I have ffmpeg installed via apt. Node and npm are running on the latest version. I also tried using the master branch of discord.js with still no luck. I tried deleting everything and reinstallling it again, it still didn't work.

1
have you tried "audio/mpeg " in type in place of ogg/opus ? try firefox and or chrome in ubuntuRobert Rowntree
@RobertRowntree still didn't workMilan

1 Answers

0
votes

As of discord.js v12 you now can only use the .play() method So your solution should be:

channel.join()
    .then(connection => {
        const stream = connection.play('/path/to/file.mp3');

        stream.on("finish", () => {
            channel.leave();
        });
    });