forked from nknandan/MuteBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
71 lines (63 loc) · 2.18 KB
/
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = '_mb';
const low = require('lowdb');
const FileSync = require('lowdb/adapters/FileSync');
const adapter = new FileSync('Database.json');
const db = low(adapter);
db.defaults({ users : {}})
.write()
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
client.user.setActivity(` ${prefix}`, { type: 'PLAYING' })
.then(presence => console.log(`Activity set to ${presence.activities[0].name}`))
.catch(console.error);
});
client.on('message', msg => {
let msgContents = msg.content.split(" ");
if (msgContents[0] === prefix){
if(msgContents[1] === "ping"){
msg.reply('Pong !');
}
if (msgContents[1] === 'start'){
const channel = msg.member.voice.channel;
if (channel){
db.set(`users.${msg.member.user.id}`, channel).write();
msg.reply('MuteBot Started !');
}else {
msg.reply("You need to be in a Voice Channel to Start MuteBot !")
}
}
if(msgContents[1] === "stop"){
db.unset(`users.${msg.member.user.id}`).write();
msg.reply('MuteBot Stopped!');
}
if(msgContents[1] === "help"){
msg.reply({embed: {
color: 3447003,
title: "MuteBot !",
fields: [
{ name: `${prefix}`, value: "start\nstop", inline: true},
{ name: "Prefix", value: "start an instance of the bot.\nstop an instance of the bot.", inline: true}
]
}
});
}
}
});
client.on('voiceStateUpdate', (voiceState, voiceState1) => {
const userId = voiceState1.member.user.id;
const channel = db.get(`users.${userId}`).value();
if(channel){
try {
channel.members.forEach((member) => {
if(member.id !== userId){
member.voice.setMute(voiceState1.member.voice.selfMute);
}
})
}catch (e) {
console.error(e);
}
}
})
client.login('token');