node.js - Discord bot node.js linux 没有声音

标签 node.js discord

我一直在尝试让机器人在 Discord 上发送声音,但我无法让它工作。我将在 Windows 上运行的相同代码复制粘贴到了我的 Arch Linux 服务器上,机器人简单地加入,然后立即离开。

这是我尝试过的:

const fs = require('fs');
client.on('message', msg => {
        var VC = msg.member.voiceChannel;
        if (!VC)
        {
            msg.channel.send('This command only works in a voice channel');
        }
        VC.join().then(connection => 
        {
            const dispatcher = connection.playFile('mysoundfile.mp3');
            dispatcher.on("end", end => {VC.leave()});
        })
}

我就是不知道出了什么问题,而且我已经对这个问题进行了长时间的谷歌研究。

谢谢。

最佳答案

通常nodejs会关心不同操作系统上的路径,但有些路径会抛出错误。我建议使用类似的东西:

const mp3File = path.join(process.cwd(), 'mysoundfile.mp3');
const dispatcher = connection.playFile(mp3File);

关于node.js - Discord bot node.js linux 没有声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53199821/

相关文章:

javascript - Heroku 'H12' Node JS 应用程序请求超时错误

javascript - Express js 函数与 api 不返回值

json - 从 .json 文件到 Mongoose 模式?

python - Discord.py - 查找有关发件人的信息

javascript -/n 不显示为换行符

javascript - 有没有办法编写一个命令来查找和显示 Google 表格中的一行内容?

javascript - node.js 错误 : connect ECONNREFUSED; response from server

node.js - Selenium 网络驱动程序。通过 selenium grid 运行测试时如何安装 chrome 扩展?

python - Discord.py 打印邀请链接

Discord.js 13 channel.join 不是一个函数