forked from fent/node-ytdl-core
/
discord.js
30 lines (27 loc) · 875 Bytes
/
discord.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Install discord.js before running this!
const Discord = require('discord.js');
const ytdl = require('..');
const client = new Discord.Client();
client.login(' Y o u r B o t T o k e n ');
client.on('ready', () => {
console.log('discord.js client ready');
});
client.on('message', message => {
if (message.content.startsWith('++play')) {
console.log('Got a song request!');
const voiceChannel = message.member.voiceChannel;
if (!voiceChannel) {
return message.reply('Please be in a voice channel first!');
}
voiceChannel.join()
.then(connnection => {
let stream = ytdl('https://www.youtube.com/watch?v=dQw4w9WgXcQ', {
filter : 'audioonly',
});
const dispatcher = connnection.playStream(stream);
dispatcher.on('end', () => {
voiceChannel.leave();
});
});
}
});