diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-03-06 20:05:04 +0100 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-03-06 20:05:04 +0100 |
commit | 4f822cd273e35fd8e368489d61b558a288826943 (patch) | |
tree | f442075901004be916c9c27d362d353fe3c1b818 /music.js | |
parent | a8e4fd12ae5dc5136239832a2b7df6a7f79b83c9 (diff) | |
download | furrybot-discord-4f822cd273e35fd8e368489d61b558a288826943.tar.xz |
Add search feature
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) } } |