aboutsummaryrefslogtreecommitdiff
path: root/bot.js
blob: 82f4444f76dce70668754be793c1c5523825a8da (plain) (blame)
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
54
55
56
57
58
const Discord = require('discord.js');
const client = new Discord.Client();
const config = require('./token.json');
const fs = require('fs');
let prefix = "!"

function fetchAudio() {
    
}

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
  console.log('Prefix:', prefix);
});

client.on('message', async msg => {
    if (!['242775871059001344'].includes(msg.author.id)) return;
    if (!msg.guild) return;
    if (msg.author.bot) return;
    if (!msg.content.startsWith(prefix)) return;
  
    let command = msg.content.split(" ")[0];
    command = command.slice(prefix.length);

  if (command == 'ping') {
    msg.reply('Pong! '  + Math.round(client.ping) + ' ms');
  }

  if (command == 'poweroff') {
      console.log("Powering off...");
      client.destroy();
      process.exit(0);
  }

  if (command == 'join') {
    // Only try to join the sender's voice channel if they are in one themselves
    if (msg.member.voice.channel) {
        console.log("Connected to voice chat...")
      const connection = await msg.member.voice.channel.join();
      connection.play('./music/4616-werq-by-kevin-macleod.mp3');
      console.log(connection)
    } else {
      msg.reply('You need to join a voice channel first!');
    }
  }

  if (command == 'leave') {
    // Only try to join the sender's voice channel if they are in one themselves
    if (msg.member.voice.channel) {
        console.log("Disconnected from voice chat...")
      const connection = await msg.member.voice.channel.leave();
    } else {
      msg.reply('You need to join a voice channel first!');
    }
  }
});

client.login(config.token);