当我试图演奏我的音乐不和谐,它不播放音乐。它使用ytdl核心和ffmpeg,我的代码是:
const Discord = require('discord.js');
const bot = new Discord.Client
const ytdl = require("ytdl-core")
const token = 'API TOKEN'
const PREFIX = '?';
var version = '1.2';
var servers = {};
bot.on('ready', () =>{
console.log('This bot is online!' + version);
})
bot.on('message', message => {
let args = message.content.substring(PREFIX.length).split(" ");
switch(args[0]){
case 'play':
function play(connection, message){
var server = servers[message.guild.id];
server.dispatcher = connection.play(ytdl(server.queue[0], {filter: "audioonly"}))
server.queue.shift();
server.dispatcher.on("end", function(){
if(server.queue[0]){
play(connection, message);
}else {
connection.disconnect();
}
});
}
if(!args[1]){
message.channel.send("You need to provide a link!")
return;
}
if(!message.member.voice.channel){
message.channel.send("You must be in a Voice Channel to play the bot!")
return;
}
if(!servers[message.guild.id]) servers[message.guild.id] = {
queue: []
}
var server = servers[message.guild.id];
server.queue.push(args[1]);
if(!message.guild.voice) message.member.voice.channel.join().then(function(connection){
play(connection, message);
})
break;
}
});
bot.login(token);每当我尝试播放一首歌时,就会发生这样的错误:
(节点:5180) UnhandledPromiseRejectionWarning:错误: FFmpeg/avconv未找到!(C:\Users\picar\Desktop\DiscordMusicBot\node_modules\prism-media\src\core\FFmpeg.js:130:11) at Function.create (C:\Users\picar\Desktop\DiscordMusicBot\node_modules\prism-media\src\core\FFmpeg.js:143:38) at new FFmpeg (C:\Users\picar\Desktop\DiscordMusicBot\node_modules\prism-media\src\core\FFmpeg.js:44:27) at AudioPlayer.playUnknown (C:\Users\picar\Desktop )\DiscordMusicBot\node_modules\discord.js\src\client\voice\player\BasePlayer.js:47:20) at VoiceConnection.play (C:\Users\picar\Desktop\DiscordMusicBot\node_modules\discord.js\src\client\voice\util\PlayInterface.js:71:28) at play (C:\Users\picar\Desktop\DiscordMusicBot\index.js:29:48) at C:\Users\picar\Desktop\DiscordMusicBot\index.js:66:17 at processTicksAndRejections (内部/进程/任务队列):97:5) (节点:5180) UnhandledPromiseRejectionWarning:未处理的承诺拒绝。此错误起源于在异步函数中抛出而不带catch块,或者拒绝使用.catch()处理的承诺。若要在未处理的允诺拒绝时终止节点进程,请使用CLI标志
--unhandled-rejections=strict(请参阅https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode)。(拒绝id: 1) (节点:5180) DEP0018 DeprecationWarning:未处理的承诺拒绝被取消。在未来,承诺不处理的拒绝将使用非零退出代码终止Node.js进程。
请帮帮忙。
发布于 2020-06-01 13:48:10
你安装FFmpeg了吗?还是固定的?
尝试做npm i ffmpeg ffmpeg-static,它应该更新一切,如果它改变了什么,让我们知道!
还请尝试安装npm i @discordjs/opus,因为它需要播放不和谐的音频:)
https://stackoverflow.com/questions/62124328
复制相似问题