-
Notifications
You must be signed in to change notification settings - Fork 0
/
discord_bot.js
30 lines (28 loc) · 915 Bytes
/
discord_bot.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
var fs = require('fs')
var Discord = require('discord.js');
var bot = new Discord.Client();
var isReady = true;
try {
var BotConfig = require("./bot.json");
} catch (e){
console.log("Please create an bot.json like bot.json.example with a bot token.\n"+e.stack);
process.exit();
}
bot.on('message', message => {
if (isReady && 0 === message.content.indexOf( BotConfig.cmd_prefix ) ) {
isReady = false;
var fileName = './' + message.content.substring( BotConfig.cmd_prefix.length ) + '.mp3';
var voiceChannel = message.member.voiceChannel;
if ( typeof voiceChannel != typeof undefined && true === fs.existsSync( fileName ) ) {
voiceChannel.join().then(connection =>
{
const dispatcher = connection.playFile( fileName );
dispatcher.on("end", end => {
voiceChannel.leave();
});
}).catch(err => console.log(err));
isReady = true;
}
}
});
bot.login( BotConfig.bot_token );