]> git.lizzy.rs Git - furrybot-discord.git/blob - music.js
Add bad apple
[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                         const channel = msg.member.voice.channel
9
10                         if (! channel)
11                                 return msg.reply("Join a voice channel you fucking moron")
12
13                         let url = urlArr.join(" ")
14
15                         try {
16                                 new URL(url)
17                         } catch {
18                                 url = "https://youtube.com/watch?v=" + (await youtubeSearchApi.GetListByKeyword(url, false, 1)).items[0].id
19                                 msg.reply("Playing this: " + url)
20                         }
21
22                         const conn = voice.joinVoiceChannel({
23                                 channelId: channel.id,
24                                 guildId: channel.guild.id,
25                                 adapterCreator: channel.guild.voiceAdapterCreator,
26                         })
27                         const player = voice.createAudioPlayer()
28
29                         player.play(voice.createAudioResource(ytdl(url, {filter: "audioonly"}), {inputType: voice.StreamType.Arbitrary}))
30                         conn.subscribe(player)
31                 }
32         }
33 }