discord.js 不播放音频文件 [英] discord.js not playing audio file

查看:18
本文介绍了discord.js 不播放音频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试播放音频文件,但由于某种原因它没有播放任何内容,它在机器人连接后立即触发 end 事件而不是 start 事件到语音频道.

I am trying to play an audio file but, for some reason it's not playing anything, it's firing end event instead of start event, right after the bot is connected to voice channel.

client.on('message', message => {
      if(message.content.startsWith('!play')) {

      if(!message.member.voiceChannel) return message.channel.send('connect to voice channel first');

      message.member.voiceChannel.join()
        .then(connection => { 

            console.log("Joined voice channel!");

            const dispatcher = connection.playFile(require("path").join(__dirname, './myfile.mp3'));

            dispatcher.on('start', () => { //not working
                dispatcher.setVolume(0.70);
                console.log("Playing");
            }); 

            dispatcher.on('error', (err) => console.log(err)); //no errors

            dispatcher.on('end', end => { //working fine
                console.log("Finished");
                console.log("End: " + end);
                message.member.voiceChannel.leave()
            });
        });

}});

推荐答案

我从 node-modules 中删除了 ffmpeg-binaries 并安装了 ffmpeg使用 sudo apt 现在工作正常.问题是,我安装了这两个库.

I removed ffmpeg-binaries from node-modules and installed ffmpeg using sudo apt and it's working fine now. The problem was that, i had both of these libraries installed.

这篇关于discord.js 不播放音频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆