当我尝试播放我的音乐不和谐机器人时,它无法播放音乐



当我尝试播放我的音乐不和谐机器人时,它不播放音乐。它使用 ytdl-core 和 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( 未处理的承诺拒绝警告:错误:FFmpeg/avconv 不是 发现! at Function.getInfo (C:\Users\picar\Desktop\DiscordMusicBotode_modules\prism-media\src\core\FFmpeg.js:130:11( at Function.create (C:\Users\picar\Desktop\DiscordMusicBotode_modules\prism-media\src\core\FFmpeg.js:143:38( at new FFmpeg (C:\Users\picar\Desktop\DiscordMusicBotode_modules\prism-media\src\core\FFmpeg.js:44:27( at AudioPlayer.playUnknown (C:\Users\picar\Desktop\DiscordMusicBotode_modules\discord.js\src\client\voice\player\BasePlayer.js:47:20( at VoiceConnection.play (C:\Users\picar\Desktop\DiscordMusicBotode_modules\discord.js\src\client\voice\util\PlayInterface.js:71:28( 在玩 (C:\Users\picar\Desktop\DiscordMusicBot\index.js:29:48( at C:\Users\picar\Desktop\DiscordMusicBot\index.js:66:17 at processTicksAndRejections (internal/process/task_queues.js:97:5( (节点:5180(未处理的承诺拒绝警告:未处理的承诺拒绝。此错误起源于异步 没有 catch 块的函数,或者拒绝承诺 不使用 .catch(( 处理。在未处理的节点进程上终止 承诺拒绝,使用 CLI 标志--unhandled-rejections=strict(见 https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode(。 (拒绝 ID:1( (节点:5180([DEP0018]弃用警告:不推荐使用未处理的承诺拒绝。将来,承诺拒绝 未处理将以非零退出终止 Node.js 进程 法典

请帮忙。

你安装了 FFmpeg 吗?还是 ffmpeg-static ?

尝试做npm i ffmpeg ffmpeg-static,它应该更新所有内容,如果它改变了什么,请告诉我们!

还要尝试安装npm i @discordjs/opus因为需要在 Discord 中播放音频:)

最新更新