Skip to content Skip to sidebar Skip to footer

Discord Bot Youtube Search, Wait For Answer Of Asynchronous Function

I have built a discord but using javascript I've got one command where I want the ability to search for a youtube video and play the first result in a voice channel. I'm using the

Solution 1:

You can run that in an async function:

voiceChannel.join().then(async connection => {
  let url = await searchYouTubeAsync(args);
  let stream = ytdl(url, { filter: 'audioonly' });
  let dispatcher = connection.playStream(stream);

  dispatcher.on('end', () => voiceChannel.leave());
  isReady = true;
})

Solution 2:

I'm almost sure that this is unactual now. However, here is the solution:

const stream = ytdl(searchYouTubeAsync(args).toString(), { filter: 'audioonly' });

xxx.toString() hepled me when I had same trouble with ytdl.

Post a Comment for "Discord Bot Youtube Search, Wait For Answer Of Asynchronous Function"