【问题标题】:Discord bot: Fix ‘FFMPEG not found’Discord bot:修复“找不到 FFMPEG”
【发布时间】:2019-07-06 13:47:25
【问题描述】:

我想让我的 Discord 机器人加入语音聊天,但每次我做到这一点时,我都会在 log(cmd) 中收到错误提示,FFMPEG not found,请帮助我。

错误图片:

这是代码:

client.on('message', message => {
  // Voice only works in guilds, if the message does not come from a guild,
  // we ignore it
  if (!message.guild) return;

  if (message.content === '/join') {
    // Only try to join the sender's voice channel if they are in one themselves
    if (message.member.voiceChannel) {
      message.member.voiceChannel.join()
        .then(connection => { // Connection is an instance of VoiceConnection
          message.reply('I have successfully connected to the channel!');
        })
        .catch(console.log);
    } else {
      message.reply('You need to join a voice channel first!');
    }
  }
});

这是我的 package.json 文件:

{
  "name": "xxxtentacion",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "dev": "nodemon index.js"
  },
  "dependencies": {
    "discord.js": "^11.4.2",
    "dotenv": "^6.2.0",
    "ffmpeg": "0.0.4",
    "opusscript": "0.0.6"
  },
  "devDependencies": {
    "nodemon": "^1.18.9"
  }
}

【问题讨论】:

  • 你有package.json吗?您在该文件中有任何 ffmpeg 相关的依赖项吗?

标签: javascript ffmpeg discord discord.js


【解决方案1】:

语音简介 discord.js 中的语音可用于许多事情,例如音乐机器人、录制或中继音频。

在 discord.js 中,您可以通过连接到 VoiceChannel 来获得 VoiceConnection 来使用语音,您可以在其中开始流式传输和接收音频。

要开始使用,请确保您拥有:

FFmpeg - npm install ffmpeg-binaries
一个作品编码器,从以下选择一个:

  • npm install node-opus(性能更好)
  • npm install opusscript(网络连接良好)

首选的 opus 引擎是 node-opus,因为它的性能明显优于 opusscript。当两者都可用时,discord.js 会自动选择 node-opus。仅建议在 node-opus 难以工作的开发环境中使用 opusscript。对于生产机器人,应该考虑使用 node-opus,尤其是当它们要在多个服务器上运行时。

【讨论】:

  • @zero298 我添加了我的 package.json 文件
【解决方案2】:

FFmpeg 是处理音频/视频/图像/字幕内容的便捷工具,在这种情况下,此工具用于从比特流的任意容器(例如 mp4、mkv、flv、ogg)中提取音频到兼容 Discord 的 VoIP 编解码器OPUS

虽然它旨在独立于平台,但对于每个平台都需要不同的程序,请注意:我只列出了我擅长的那些平台。

GNU/Linux

您主要使用包管理器来安装它及其依赖项,或者您可以使用here中描述的步骤手动编译代码的方式。

# Ubuntu / Debian / Linux Mint
sudo apt install ffmpeg

# ArchLinux / Manjaro / Anarchy
sudo pacman -S ffmpeg

# Gentoo / Funtoo
USE=opus sudo emerge ffmpeg

窗口

Windows 不像 GNU/Linux 那样容易,你要么手动满足所有依赖项,然后用 MSVC 自己编译所有东西,要么使用 Cygwin 或 Msys2 编译。 另一种方法是从Zeranoe 的网站下载预编译的Windows 二进制文件。 由于Zeranoe 的网站已关闭,请从Gyan 的网站或其他任何地方下载。

这将为您下载一个 Zip 存档,您必须提取并复制 bin/ 文件夹的所有内容,这些是 FFmpeg 二进制文件。或者,将它们存储在 PATH 环境变量中列出的文件路径中,以便在 shell 中以 ffmpeg 的形式运行。

【讨论】:

    【解决方案3】:

    我在 Discord.js 中播放流时遇到问题,即使我安装了 ffmpeg,所以这里有一个可能的修复,如果 ffmpeg 命令不能在 CMD 中单独运行,那么至少在 Windows 中,然后我转到第 115 行的 node_modules\prism-media\src\core\FFmpeg.js 并且每个可能的目录都有一个数组,例如 ffmpeg,所以我从

    }, 'ffmpeg', 'avconv', './ffmpeg', './avconv'];
    

    }, 'ffmpeg', 'avconv', './ffmpeg', 'C:/ffmpeg/ffmpeg', './avconv'];
    

    而且效果很好! :>

    【讨论】:

      猜你喜欢
      • 2019-08-12
      • 2019-11-22
      • 2018-07-16
      • 2020-07-13
      • 1970-01-01
      • 2017-11-05
      • 2021-10-24
      • 2021-07-25
      • 1970-01-01
      相关资源
      最近更新 更多