K
K
Kirill2020-10-09 21:08:38
YouTube
Kirill, 2020-10-09 21:08:38

Why is Discord JS 12 music not playing?

const Discord = require('discord.js');
const ytdl = require('ytdl-core');
const QuickYtSearch = require('quick-yt-search'); // Require the package
const YoutubeSearcher = new QuickYtSearch({
    YtApiKey: 'Тут есть апи' // Place your YouTube API key here
});
module.exports = {
  name: 'play',
  description: 'Plays a song.',
  execute(message, args) {
        const voiceChannel = message.member.voice.channel

        args = message.content.split(' '); // Занесли в массив всё содержание сообщения

    args.splice(0, 1); // Начиная с позиции 0, удалили 2 элемента из массива

    args = args.join(' '); // Объединили все элементы в массиве

        if (!voiceChannel) return message.reply('Войдите в голосовой канал!')
        const permissions = voiceChannel.permissionsFor(message.client.user)
        if (!permissions.has('CONNECT')) return message.reply('У меня нет прав для того, чтобы присоединиться к каналу!')
        if (!permissions.has('SPEAK')) return message.reply('Я не могу проигрывать музыку!')

        YoutubeSearcher.getVideo(args).then(video => {
            voiceChannel.join().then(connection => {
                const stream = ytdl(video.url, { filter: 'audioonly' });
                const dispatcher = connection.play(stream);
    
                dispatcher.on('finish', () => voiceChannel.leave());
            });
        });
  },
};

(node:19996) UnhandledPromiseRejectionWarning: Error: FFmpeg/avconv not found!
    at Function.getInfo (C:\Users\Кирилл\Documents\Дискорд боты\music-bot\node_modules\prism-media\src\core\FFmpeg.js:130:11)
    at Function.create (C:\Users\Кирилл\Documents\Дискорд боты\music-bot\node_modules\prism-media\src\core\FFmpeg.js:143:38)
    at new FFmpeg (C:\Users\Кирилл\Documents\Дискорд боты\music-bot\node_modules\prism-media\src\core\FFmpeg.js:44:27)
    at AudioPlayer.playUnknown (C:\Users\Кирилл\Documents\Дискорд боты\music-bot\node_modules\discord.js\src\client\voice\player\BasePlayer.js:47:20)
    at VoiceConnection.play (C:\Users\Кирилл\Documents\Дискорд боты\music-bot\node_modules\discord.js\src\client\voice\util\PlayInterface.js:71:28)
    at C:\Users\Кирилл\Documents\Дискорд боты\music-bot\commands\play.js:27:47
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:19996) 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:19996) [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.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Nevzorov, 2020-10-10
@KIRIK12

UnhandledPromiseRejectionWarning: Error: FFmpeg/avconv not found!

To play music using the library you are using, FFmpeg or avconv is required. Download the FFmpeg/avconv executable and place it in the PATH/folder of the bot executable.
Links to ffmpeg builds:
https://www.gyan.dev/ffmpeg/builds/
https://github.com/BtbN/FFmpeg-Builds/releases

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question