找不到FFMPEG,因为不再支持FFMPEG二进制文件

时间:2019-11-17 21:19:23

标签: javascript ffmpeg discord

我一直在尝试创建Discord机器人,但是由于出现错误Error: FFMPEG not found,它无法连接到语音通道。有没有办法解决使用FFMPEG二进制文件或我可以手动安装的旧版本的问题?

const Discord = require('discord.js');
const {
	prefix,
	token,
} = require('./config.json');
const ytdl = require('ytdl-core');

const client = new Discord.Client();

const queue = new Map();

client.once('ready', () => {
	console.log('Ready!');
});

client.once('reconnecting', () => {
	console.log('Reconnecting!');
});

client.once('disconnect', () => {
	console.log('Disconnect!');
});

client.on('message', async message => {
	if (message.author.bot) return;
	if (!message.content.startsWith(prefix)) return;

	const serverQueue = queue.get(message.guild.id);

	if (message.content.startsWith(`${prefix}play`)) {
		execute(message, serverQueue);
		return;
	} else if (message.content.startsWith(`${prefix}skip`)) {
		skip(message, serverQueue);
		return;
	} else if (message.content.startsWith(`${prefix}stop`)) {
		stop(message, serverQueue);
		return;
	} else {
		message.channel.send('You need to enter a valid command!')
	}
});

async function execute(message, serverQueue) {
	const args = message.content.split(' ');

	const voiceChannel = message.member.voiceChannel;
	if (!voiceChannel) return message.channel.send('You need to be in a voice channel to play music!');
	const permissions = voiceChannel.permissionsFor(message.client.user);
	if (!permissions.has('CONNECT') || !permissions.has('SPEAK')) {
		return message.channel.send('I need the permissions to join and speak in your voice channel!');
	}

	const songInfo = await ytdl.getInfo(args[1]);
	const song = {
		title: songInfo.title,
		url: songInfo.video_url,
	};

	if (!serverQueue) {
		const queueContruct = {
			textChannel: message.channel,
			voiceChannel: voiceChannel,
			connection: null,
			songs: [],
			volume: 5,
			playing: true,
		};

		queue.set(message.guild.id, queueContruct);

		queueContruct.songs.push(song);

		try {
			var connection = await voiceChannel.join();
			queueContruct.connection = connection;
			play(message.guild, queueContruct.songs[0]);
		} catch (err) {
			console.log(err);
			queue.delete(message.guild.id);
			return message.channel.send(err);
		}
	} else {
		serverQueue.songs.push(song);
		console.log(serverQueue.songs);
		return message.channel.send(`${song.title} has been added to the queue!`);
	}

}

function skip(message, serverQueue) {
	if (!message.member.voiceChannel) return message.channel.send('You have to be in a voice channel to stop the music!');
	if (!serverQueue) return message.channel.send('There is no song that I could skip!');
	serverQueue.connection.dispatcher.end();
}

function stop(message, serverQueue) {
	if (!message.member.voiceChannel) return message.channel.send('You have to be in a voice channel to stop the music!');
	serverQueue.songs = [];
	serverQueue.connection.dispatcher.end();
}

function play(guild, song) {
	const serverQueue = queue.get(guild.id);

	if (!song) {
		serverQueue.voiceChannel.leave();
		queue.delete(guild.id);
		return;
	}

	const dispatcher = serverQueue.connection.playStream(ytdl(song.url))
		.on('end', () => {
			console.log('Music ended!');
			serverQueue.songs.shift();
			play(guild, serverQueue.songs[0]);
		})
		.on('error', error => {
			console.error(error);
		});
	dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
}

client.login(token);

这是我尝试“!play”后出现的错误。

D:\Bot-Files-Test>node index.js
Ready!
Error: FFMPEG not found
    at Function.selectFfmpegCommand (D:\Bot-Files-Test\node_modules\prism-media\src\transcoders\ffmpeg\Ffmpeg.js:46:13)
    at new FfmpegTranscoder (D:\Bot-Files-Test\node_modules\prism-media\src\transcoders\ffmpeg\Ffmpeg.js:7:37)
    at new MediaTranscoder (D:\Bot-Files-Test\node_modules\prism-media\src\transcoders\MediaTranscoder.js:10:19)
    at new Prism (D:\Bot-Files-Test\node_modules\prism-media\src\Prism.js:5:23)
    at new VoiceConnection (D:\Bot-Files-Test\node_modules\discord.js\src\client\voice\VoiceConnection.js:46:18)
    at D:\Bot-Files-Test\node_modules\discord.js\src\client\voice\ClientVoiceManager.js:63:22
    at new Promise (<anonymous>)
    at ClientVoiceManager.joinChannel (D:\Bot-Files-Test\node_modules\discord.js\src\client\voice\ClientVoiceManager.js:45:12)
    at VoiceChannel.join (D:\Bot-Files-Test\node_modules\discord.js\src\structures\VoiceChannel.js:130:30)
    at execute (D:\Bot-Files-Test\index.js:75:40)
(node:9108) UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message
    at D:\Bot-Files-Test\node_modules\discord.js\src\client\rest\RequestHandlers\Sequential.js:85:15
    at D:\Bot-Files-Test\node_modules\snekfetch\src\index.js:215:21
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:9108) 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(). (rejection id: 3)
(node:9108) [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.

0 个答案:

没有答案