我一直在尝试让机器人在 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/