I am having an issue with playing sounds in discord.js

351 Views Asked by At

So, I am having problems when I try to run a sound on discord.js.

Below is the code:

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)

The error I get is:

(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.

I've seen previous questions asked here before. None of the answers were concise, or they included words that suggested uncertainty, and most of them didn't work.

0

There are 0 best solutions below