diff options
Diffstat (limited to 'music.js')
-rw-r--r-- | music.js | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -1,9 +1,18 @@ const ytdl = require("ytdl-core") const voice = require("@discordjs/voice") +const youtubeSearchApi = require("youtube-search-api") module.exports = { play: { - func: (msg, url) => { + func: async (msg, urlArr) => { + let url = urlArr.join(" ") + + try { + new URL(url) + } catch { + url = "https://youtube.com/watch?v=" + (await youtubeSearchApi.GetListByKeyword(url, false, 1)).items[0].id + } + const channel = msg.member.voice.channel if (! channel) @@ -16,7 +25,7 @@ module.exports = { }) const player = voice.createAudioPlayer() - player.play(voice.createAudioResource(ytdl(url.join(" "), {filter: "audioonly"}), {inputType: voice.StreamType.Arbitrary})) + player.play(voice.createAudioResource(ytdl(url, {filter: "audioonly"}), {inputType: voice.StreamType.Arbitrary})) conn.subscribe(player) } } |