Showing
2 changed files
with
35 additions
and
4 deletions
| 1 | -const {prefix, token} = require('./config.json'); | 1 | +const {prefix, token, youtubeAPI} = require('./config.json'); |
| 2 | const Discord = require("discord.js") // npm install discord.js 필요 | 2 | const Discord = require("discord.js") // npm install discord.js 필요 |
| 3 | +const {MessageEmbed} = require('discord.js'); | ||
| 3 | const client = new Discord.Client() | 4 | const client = new Discord.Client() |
| 4 | const fs = require('fs'); // 파일 입출력 모듈 | 5 | const fs = require('fs'); // 파일 입출력 모듈 |
| 5 | const internal = require("stream"); | 6 | const internal = require("stream"); |
| 6 | var now = new Date(); // 현재날짜 및 시간 객체 | 7 | var now = new Date(); // 현재날짜 및 시간 객체 |
| 7 | const moment = require('moment') // npm install --save moment 필요 (디데이 출력 모듈) | 8 | const moment = require('moment') // npm install --save moment 필요 (디데이 출력 모듈) |
| 9 | +const Youtube = require('simple-youtube-api'); // npm install simple-youtube-api | ||
| 10 | +const youtube = new Youtube(youtubeAPI); | ||
| 11 | +const ytdl = require('ytdl-core'); // npm install ytdl-core | ||
| 12 | +const { getVideoID } = require('ytdl-core'); | ||
| 8 | 13 | ||
| 9 | //npm install discord.js @discord/opus 필요 | 14 | //npm install discord.js @discord/opus 필요 |
| 10 | //npm install --save ffmpeg-binaries 필요 | 15 | //npm install --save ffmpeg-binaries 필요 |
| ... | @@ -197,10 +202,10 @@ client.on("message", msg => { | ... | @@ -197,10 +202,10 @@ client.on("message", msg => { |
| 197 | msg.member.voice.channel.join() | 202 | msg.member.voice.channel.join() |
| 198 | .then(connection => { | 203 | .then(connection => { |
| 199 | msg.reply("재생한다!"); | 204 | msg.reply("재생한다!"); |
| 200 | - const dispatcher = connection.play("music/square.mp3"); | 205 | + const dispatcher = connection.play("music/comfortable.mp3"); |
| 201 | dispatcher.on("end", end => {}); | 206 | dispatcher.on("end", end => {}); |
| 202 | }) | 207 | }) |
| 203 | - .catch(console.log); | 208 | + .catch(console.log); |
| 204 | } else { | 209 | } else { |
| 205 | msg.reply("먼저 보이스채널에 입장해주세요."); | 210 | msg.reply("먼저 보이스채널에 입장해주세요."); |
| 206 | } | 211 | } |
| ... | @@ -222,6 +227,31 @@ client.on("message", msg => { | ... | @@ -222,6 +227,31 @@ client.on("message", msg => { |
| 222 | 227 | ||
| 223 | 228 | ||
| 224 | 229 | ||
| 230 | + //유튜브 음악 재생 | ||
| 231 | + if (msg.content.startsWith(prefix+"재생")) { | ||
| 232 | + var msgData = msg.toString().split(" "); | ||
| 233 | + if (msg.member.voice.channel) { | ||
| 234 | + msg.member.voice.channel.join() | ||
| 235 | + .then(connection => { | ||
| 236 | + youtube.searchVideos(msgData[1]).then(results => { // 유튜브에 msgData[1] 검색 | ||
| 237 | + const play = connection.play(ytdl("https://www.youtube.com/watch?v="+results[0].id)); | ||
| 238 | + play.on('start', () => { | ||
| 239 | + //내용 추가 필요 | ||
| 240 | + }) | ||
| 241 | + console.log(results[0].title); | ||
| 242 | + msg.reply(results[0].title + " 을 재생한다!"); | ||
| 243 | + }) | ||
| 244 | + | ||
| 245 | + }) | ||
| 246 | + .catch(console.log); | ||
| 247 | + } else { | ||
| 248 | + msg.reply("먼저 보이스채널에 입장해주세요."); | ||
| 249 | + } | ||
| 250 | + } // 유튜브 음악 재생 end | ||
| 251 | + | ||
| 252 | + | ||
| 253 | + | ||
| 254 | + | ||
| 225 | 255 | ||
| 226 | }) | 256 | }) |
| 227 | 257 | ... | ... |
-
Please register or login to post a comment