【问题标题】:Discord.js not playing mp3 file on Ubuntu 18.04Discord.js 无法在 Ubuntu 18.04 上播放 mp3 文件
【发布时间】:2020-04-28 06:12:23
【问题描述】:

我在 discord js 中有一个不和谐的机器人。我有一个命令可以在语音频道中播放 mp3 文件。

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

如果我在我的 Windows 电脑上运行机器人,一切正常。机器人加入频道,播放文件并再次离开。如果我在我的 Ubuntu 18.04 VM 上运行机器人,机器人会加入并立即断开连接而不播放文件。

mp3 文件的路径是绝对路径。我已经尝试过使用 connection.playFile(path) 来代替同样的问题。我尝试使用 opusscript,并尝试使用 node-opus。我通过apt安装了ffmpeg。 Node 和 npm 在最新版本上运行。我还尝试使用 discord.js 的 master 分支,但仍然没有运气。我尝试删除所有内容并重新安装它,但仍然无法正常工作。

【问题讨论】:

  • 你试过用“audio/mpeg”代替ogg/opus吗?在 ubuntu 中尝试 firefox 或 chrome
  • @RobertRowntree 仍然没有工作

标签: node.js discord discord.js


【解决方案1】:

从 discord.js v12 开始,您现在只能使用 .play() 方法 所以你的解决方案应该是:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-27
    • 1970-01-01
    相关资源
    最近更新 更多