]> git.lizzy.rs Git - furrybot-discord.git/blob - music.js
Add search feature
[furrybot-discord.git] / music.js
1 const ytdl = require("ytdl-core")
2 const voice = require("@discordjs/voice")
3 const youtubeSearchApi = require("youtube-search-api")
4
5 module.exports = {
6         play: {
7                 func: async (msg, urlArr) => {
8                         let url = urlArr.join(" ")
9
10                         try {
11                                 new URL(url)
12                         } catch {
13                                 url = "https://youtube.com/watch?v=" + (await youtubeSearchApi.GetListByKeyword(url, false, 1)).items[0].id
14                         }
15
16                         const channel = msg.member.voice.channel
17
18                         if (! channel)
19                                 return msg.reply("Join a voice channel you fucking moron")
20
21                         const conn = voice.joinVoiceChannel({
22                                 channelId: channel.id,
23                                 guildId: channel.guild.id,
24                                 adapterCreator: channel.guild.voiceAdapterCreator,
25                         })
26                         const player = voice.createAudioPlayer()
27
28                         player.play(voice.createAudioResource(ytdl(url, {filter: "audioonly"}), {inputType: voice.StreamType.Arbitrary}))
29                         conn.subscribe(player)
30                 }
31         }
32 }