Kieran Julien
Kieran Julien

Reputation: 43

Bot leaving voice channel when trying to play music and giving an "undefined" error

I'm currently working on a discord bot with some music commands. It works by using the "play" command. If you run it it will search on youtube for your given argument (using ytdl-core and simple-youtube-api). It gives you 5 video results and you have to choose a number (from 1-5)

But when it joins the voice channel to go play music it randomly leaves and sends "undefined" in chat without any more information or errors. I am currently using a VPS to host this bot, if I host on my computer "some" music plays, but still a lot wont work, but on the VPS none of the music works. I get no errors besides undefined" but I don't know here it came from because there are no given lines. I tried reinstalling the using packages again but none of it worked.

Here is my code:

https://pastebin.com/Eerm3sHH

function play(guild, song) {
  const serverQueue = queue.get(guild.id);

  if (!song) {
    serverQueue.voiceChannel.leave();
    queue.delete(guild.id);
    return;
  }

  const dispatcher = serverQueue.connection.playStream(ytdl(song.url))
    .on('end', reason => {
      if (reason === 'Stream is not generating quickly enough.') console.log('Song ended.');
       serverQueue.songs.shift();
       play(guild, serverQueue.songs[0]);
     })
     .on('error', error => console.log(error));
     dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);

     serverQueue.textChannel.send(`**${song.title}**, is now playing!`);
   }
}

I think the issue is somewhere around here.

Upvotes: 4

Views: 827

Answers (1)

Adam Kerik
Adam Kerik

Reputation: 491

Most likely, you are missing FFMPEG which ytdl-core depends on.

Upvotes: 1

Related Questions