Reputation: 43
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:
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