Discord.js 音乐机器人:TypeError:this.inputMedia.pipe 不是函数
Posted
技术标签:
【中文标题】Discord.js 音乐机器人:TypeError:this.inputMedia.pipe 不是函数【英文标题】:Discord.js music bot: TypeError: this.inputMedia.pipe is not a function 【发布时间】:2019-10-22 22:45:18 【问题描述】:我正在使用 Discord.js 编写音乐 Discord 机器人。该机器人使用 ytdl-core、node-opus,并且我在我的操作系统(Ubuntu 19.04)上安装了 ffmpeg。当我尝试让机器人加入语音频道并开始播放 YouTube URL 时,它会引发以下错误:
TypeError: this.inputMedia.pipe is not a function
at FfmpegProcess.connectStream (/home/ivan/.../node_modules/discord.js/node_modules/prism-media/src/transcoders/ffmpeg/FfmpegProcess.js:73:21)
at new FfmpegProcess (/home/ivan/.../node_modules/discord.js/node_modules/prism-media/src/transcoders/ffmpeg/FfmpegProcess.js:28:14)
at FfmpegTranscoder.transcode (/home/ivan/.../node_modules/discord.js/node_modules/prism-media/src/transcoders/ffmpeg/Ffmpeg.js:34:18)
at MediaTranscoder.transcode (/home/ivan/.../node_modules/discord.js/node_modules/prism-media/src/transcoders/MediaTranscoder.js:27:31)
at Prism.transcode (/home/ivan/.../node_modules/discord.js/node_modules/prism-media/src/Prism.js:13:28)
at AudioPlayer.playUnknownStream (/home/ivan/.../node_modules/discord.js/src/client/voice/player/AudioPlayer.js:97:35)
at VoiceConnection.playStream (/home/ivan/.../node_modules/discord.js/src/client/voice/VoiceConnection.js:478:24)
at voiceChannel.join.then.connection (/home/ivan/.../commands/play.js:32:47)
at process._tickCallback (internal/process/next_tick.js:68:7)
这是我的代码:
const ytdl = require("ytdl-core");
exports.run = (client, message, args, config) =>
return new Promise((resolve, reject) =>
if (args.length !== 1)
message.channel.send("Play command takes 1 YouTube link.");
reject("Wrong number of arguments");
return;
const voiceChannel = message.member.voiceChannel;
if(!voiceChannel)
message.channel.send("You need to connect to a voice channel first");
reject("Not connected to voice channel");
return;
const perms = voiceChannel.permissionsFor(message.client.user);
if (!perms.has("CONNECT"))
message.channel.send("You need to add the 'connect' permission for this bot");
reject("NO CONNECT PERMISSION");
return;
if (!perms.has("SPEAK"))
message.channel.send("You need to add the 'speak' permission for this bot");
reject("NO SPEAK PERMISSION");
return;
const streamOptions = seek: 0, volume: 1, passes: 2 ;
voiceChannel.join()
.then(connection =>
const stream = ytdl(args[0], filter: 'audioonly');
const dispatcher = connection.playStream(ytdl, streamOptions);
dispatcher.on("end", reason =>
console.log("reason: " + reason);
voiceChannel.leave();
)
dispatcher.on("error", err =>
console.log(err);
)
)
.catch(err => console.log(err));
);
我尝试重新安装 ffmpeg、node 和 npm、discord.js 和 node-opus。我安装了最新版本的 Discord.js,以及 ffmpeg 版本 4.1.3-0ubuntu1。有人有什么建议吗?
谢谢。
【问题讨论】:
【参考方案1】:发现了问题,在以下几行:
const stream = ytdl(args[0], filter: 'audioonly');
const dispatcher = connection.playStream(ytdl, streamOptions);
正确的代码是
const stream = ytdl(args[0], filter: 'audioonly');
const dispatcher = connection.playStream(stream, streamOptions);
编辑:更正蒸汽流
【讨论】:
以上是关于Discord.js 音乐机器人:TypeError:this.inputMedia.pipe 不是函数的主要内容,如果未能解决你的问题,请参考以下文章
Discord.js 音乐机器人:TypeError:this.inputMedia.pipe 不是函数
从 twitch bot 调用 Discord.js 音乐问题找到语音频道
Discord JS 音乐机器人 - .message.member.voiceChannel.join() 不工作
不断收到 DiscordAPIError:在 Discord.js 中的音乐机器人上使用 reconlx 的分页执行队列命令时出现未知交互