gpt4 book ai didi

javascript - 当我尝试播放 Music Discord Bot 时,它不播放音乐

转载 作者:行者123 更新时间:2023-12-04 22:48:01 30 4
gpt4 key购买 nike

当我尝试播放我的 Music Discord Bot 时,它不播放音乐。它使用 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);
每当我尝试播放歌曲时,都会发生此错误:

(node:5180) UnhandledPromiseRejectionWarning: Error: FFmpeg/avconv notfound!at Function.getInfo (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:17at processTicksAndRejections (internal/process/task_queues.js:97:5)(node:5180) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an asyncfunction without a catch block, or by rejecting a promise which wasnot handled with .catch(). To terminate the node process on unhandledpromise rejection, use the CLI flag --unhandled-rejections=strict(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode).(rejection id: 1)(node:5180) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that arenot handled will terminate the Node.js process with a non-zero exitcode


请帮忙。

最佳答案

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

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

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

关于javascript - 当我尝试播放 Music Discord Bot 时,它不播放音乐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62124328/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com