aboutsummaryrefslogtreecommitdiff
path: root/music.js
diff options
context:
space:
mode:
Diffstat (limited to 'music.js')
-rw-r--r--music.js13
1 files changed, 11 insertions, 2 deletions
diff --git a/music.js b/music.js
index c182a5e..50bba47 100644
--- a/music.js
+++ b/music.js
@@ -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)
}
}