【问题标题】:Discord bot node.js linux no soundDiscord bot node.js linux没有声音
【发布时间】:2019-04-11 11:51:35
【问题描述】:

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

这是我尝试过的:

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()});
        })
}

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

谢谢。

【问题讨论】:

  • 您确定文件mysoundfile.mp3 存在于您的服务器上吗?
  • 是的,我确定我已经将计算机上的目录复制/粘贴到它上面

标签: node.js discord


【解决方案1】:

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

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

【讨论】:

  • 首先感谢您的回答。不幸的是,机器人会立即加入/离开。
猜你喜欢
  • 2020-09-12
  • 2021-11-07
  • 2021-12-26
  • 1970-01-01
  • 2022-12-11
  • 2021-12-16
  • 2020-04-01
  • 2021-04-15
相关资源
最近更新 更多