title: Discord.js music bot: TypeError: this.inputMedia.pipe is not a function
body: <p>I'm writing a music Discord bot using Discord.js. The bot uses ytdl-core, node-opus, and I have installed ffmpeg on my OS (Ubuntu 19.04). When I try to make the bot join a voice channel and start playing a YouTube URL, it throws the following error:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>const ytdl = require("ytdl-core");
  
  exports.run = (client, message, args, config) =&gt; {
      return new Promise((resolve, reject) =&gt; {
          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 =&gt; {
                  const stream = ytdl(args[0], {filter: 'audioonly'});
                  const dispatcher = connection.playStream(ytdl, streamOptions);
                  dispatcher.on("end", reason =&gt; {
                      console.log("reason: " + reason);
                      voiceChannel.leave();
                  })
                  dispatcher.on("error", err =&gt; {
                      console.log(err);
                  })
              })
          .catch(err =&gt; console.log(err));
      });    
  }
  </code></pre>
  
  <p>I have tried reinstalling ffmpeg, node and npm, discord.js and node-opus. I have the newest version of Discord.js installed, and ffmpeg version 4.1.3-0ubuntu1. Anyone have any suggestions? </p>
  
  <p>Thanks.</p>