-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (49 loc) · 1.94 KB
/
index.js
File metadata and controls
61 lines (49 loc) · 1.94 KB
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
59
60
61
const Discord = require('discord.js');
const config = require("./config.json");
const fs = require('fs')
const client = new Discord.Client();
// These are the possible time intervals, change to whatever you want.
var timeArray = new Array(30000, 70000, 40000, 90000, 15000, 7000, 20000, 80000);
const prefix = config.prefix;
var voiceChannel;
client.once('ready', () => {
console.log("online");
});
client.on('message', message => {
if (!message.member.voice.channel || !message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
voiceChannel = message.member.voice.channel;
var timer;
if (command === 'join') {
message.reply("*joining*");
console.log(`${new Date().toLocaleTimeString([], { hour: '2-digit', minute: "2-digit" })} - Joined VC`)
var last = -1;
voiceChannel.join().then(connection =>{
// Play a sound on join
connection.play(`audio/0.mp3`);
function play() {
let file = Math.floor(Math.random() * fs.readdirSync('audio').length);
while (file == last) {
file = Math.floor(Math.random() * fs.readdirSync('audio').length);
}
console.log(`playing file: ${file}.mp3`)
connection.play(`audio/${file}.mp3`);
timer = setTimeout(play, randRange(timeArray));
last = file;
}
// waiting 5 seconds to play another sound, change to whatever you want
timer = setTimeout(play, 5000);
}).catch(err => console.log(err));
} else if (command === 'leave') {
message.reply("*leaving*");
if(timer !== undefined) clearTimeout(timer);
voiceChannel.leave();
console.log(`${new Date().toLocaleTimeString([], { hour: '2-digit', minute: "2-digit" })} - Disconnected from VC`)
}
});
function randRange(rarray) {
var newTime = rarray[Math.floor(rarray.length * Math.random())];
return newTime;
}
client.login(config.token);