我正在开发一个播放音乐的discord.js机器人。这个想法是,用户可以键入“ X play”(X是机器人的前缀)来使机器人加入指挥官所在的语音通道。或者,用户可以键入“ X play [YouTube链接]”使用YTDL播放YouTube视频中的音频。到目前为止,该漫游器可以正常加入该频道。但是,当我附加一个链接时,会返回一个非常复杂的错误,我根本根本不理解。我已经参考过文档和帮助论坛,但是与我的问题无关。我已经附加了命令模块。
const Commando = require('discord.js-commando');
const YTDL = require('ytdl-core');
function Play(connection, message)
{
var server = servers[message.guild.id];
server.dispatcher = connection.playStream(YTDL(server.queue[0], {filter: "audioonly"}));
server.queue.shift();
server.dispatcher.on("end", function(){
if(server.queue[0])
{
Play(connection, message);
}
else
{
connection.disconnect();
}
});
}
class JoinChannelCommand extends Commando.Command
{
constructor(client)
{
super(client,{
name: 'play',
group: 'simple',
memberName: 'play',
description: 'Plays the audio from a youtube link'
});
}
async run(message, args)
{
if(message.member.voiceChannel)
{
if(!message.guild.voiceConnection)
{
if(!servers[message.guild.id])
{
servers[message.guild.id] = {queue: []}
}
message.member.voiceChannel.join()
.then(connection =>{
var server = servers[message.guild.id];
message.reply("Successfully joined!");
server.queue.push(args);
Play(connection, message);
})
}
}
else
{
message.reply("ERROR: Not connected to voice channel");
}
}
}
module.exports = JoinChannelCommand;
当我键入“ X play”时,机器人将加入频道。当我键入“ X play [link]”时,该机器人会加入但不播放音乐。控制台返回:
(node:5136) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string. Received type object
at validateString (internal/validators.js:125:11)
at normalizeSpawnArguments (child_process.js:414:3)
at Object.spawn (child_process.js:553:16)
at new FfmpegProcess (C:\My Discord Bots\XyloBot\node_modules\prism-media\src\transcoders\ffmpeg\FfmpegProcess.js:14:33)
at FfmpegTranscoder.transcode (C:\My Discord Bots\XyloBot\node_modules\prism-media\src\transcoders\ffmpeg\Ffmpeg.js:34:18)
at MediaTranscoder.transcode (C:\My Discord Bots\XyloBot\node_modules\prism-media\src\transcoders\MediaTranscoder.js:27:31)
at Prism.transcode (C:\My Discord Bots\XyloBot\node_modules\prism-media\src\Prism.js:13:28)
at AudioPlayer.playUnknownStream (C:\My Discord Bots\XyloBot\node_modules\discord.js\src\client\voice\player\AudioPlayer.js:97:35)
at VoiceConnection.playStream (C:\My Discord Bots\XyloBot\node_modules\discord.js\src\client\voice\VoiceConnection.js:478:24)
at Play (C:\My Discord Bots\XyloBot\commands\music\join.js:7:36)
(node:5136) 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: 1)
(node:5136) [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.
很长一段代码等的道歉,但是这远远超出了我的能力范围。任何帮助都将受到赞赏。