首页 > 解决方案 > 我在 discord.js 中播放声音时遇到问题

问题描述

因此,当我尝试在 discord.js 上运行声音时遇到问题。

下面是代码:

const Discord = require('discord.js')
const client = new Discord.Client()
const {token,prefix} = require('../../config.json')
const cmd = __filename.slice(__dirname.length + 1, -3).trim()

client.on('message', message => {
  function embed(title, content) {
    message.channel.send({'embed':{'title': title,'description': content}})
  }
  if (!message.content.startsWith(prefix)) return
  if (message.content.split(' ')[0].slice(prefix.length).trim() != cmd) return
  const args = message.content.split(' ').shift()
  const voiceChannel = message.member.voice.channel
  if (typeof voiceChannel === 'undefined') return embed('Error','You are not in a voice channel.')
  voiceChannel.join()
  .then(connection => {
    console.log(connection)
    connection.play('../sfx/sfx_mute.mp3')
  });
});
client.login(token)

我得到的错误是:

(node:27912) UnhandledPromiseRejectionWarning: Error: FFmpeg/avconv not found!
    at Function.getInfo (C:\Users\-\OneDrive\Desktop\AmongBot\node_modules\prism-media\src\core\FFmpeg.js:130:11)
    at Function.create (C:\Users\-\OneDrive\Desktop\AmongBot\node_modules\prism-media\src\core\FFmpeg.js:143:38)
    at new FFmpeg (C:\Users\-\OneDrive\Desktop\AmongBot\node_modules\prism-media\src\core\FFmpeg.js:44:27)
    at AudioPlayer.playUnknown (C:\Users\-\OneDrive\Desktop\AmongBot\node_modules\discord.js\src\client\voice\player\BasePlayer.js:47:20)
    at VoiceConnection.play (C:\Users\-\OneDrive\Desktop\AmongBot\node_modules\discord.js\src\client\voice\util\PlayInterface.js:71:28)
    at C:\Users\-\OneDrive\Desktop\AmongBot\src\Commands\init.js:18:16
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:27912) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:27912) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

我以前在这里看到过以前提出的问题。没有一个答案是简明扼要的,或者它们包含暗示不确定性的词语,而且大多数都不起作用。

标签: javascriptnode.jsffmpegdiscord.jsavconv

解决方案


推荐阅读