repl.it
@rshetty/

Ma Bot

Nodejs

No description

fork
loading
Files
  • index.js
  • images
  • auth.json
  • matthews_ma.mp3
  • Packager files
  • package-lock.json
  • package.json
index.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var Discord = require('discord.js');
var logger = require('winston');
const fs = require('fs');

let rawdata = fs.readFileSync('auth.json');
let auth = JSON.parse(rawdata);
// Configure logger settings
logger.remove(logger.transports.Console);
logger.add(new logger.transports.Console, {
    colorize: true
});
logger.level = 'debug';
// Initialize Discord Bot
var bot = new Discord.Client();
bot.login(auth.token);
files = fs.readdirSync('/home/runner/images/');
bot.on('ready', function (evt) {
    logger.info('Connected');
    logger.info('Logged in as: ');
    logger.info(bot.username + ' - (' + bot.id + ')');
});

bot.on('message', async function (message) {
    // Our bot needs to know if it will execute a command
    // It will listen for messages that will start with `!`
    if (message.content.substring(0, 3) == '!ma') {
        var args = message.content.substring(4).split(' ');
        var cmd = args[0];
        args = args.splice(1);
        switch(cmd) {
            case 'help':
								bot.channels.get(message.channel.id).send(`lol, you can use one of the following commands to speak to my Holy presence.\n\n 'pic' - gives a random picture of my sexy bod \n 'join [vc]' - replace [vc] with the name of a voice channel and I will connect, bestowing your ears with my creamy voice. \n\n That's literally all i can do lmao`);
						break;
            case 'pic':
								let chosenFile = files[Math.floor(Math.random() * files.length)]
                bot.channels.get(message.channel.id).send("Here is our Lord and Saviour:", {files: ["images/" + chosenFile]});
            break;
						case 'vc':
								var VC = message.member.voiceChannel;
								if (!VC){
										return message.reply("lmao you gotta be in a voice channel my chigga!")}
								 VC.join().then(function(connection){
										console.log("ok");
										const dispatcher = connection.playFile('/home/runner/matthews_ma.mp3');
										dispatcher.on("end", end => {VC.leave()});
								}).catch(console.error);
								console.log("hm")
						break;
						default:
								bot.channels.get(message.channel.id).send(`lmao, you haven't typed in a recognizable command lol. Try "!ma help".`);
         }
     }
});