-
Notifications
You must be signed in to change notification settings - Fork 1
/
mbot.js
96 lines (74 loc) · 2.29 KB
/
mbot.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const Discord = require("discord.js");
const { prefix, token, guildId } = require("./config.json");
const fs = require("fs");
const cron = require("cron");
const ytdl = require("ytdl-core");
const client = new Discord.Client();
const active = new Map();
client.commands = new Discord.Collection();
const command_files = fs.readdirSync("./commands").filter(file => file.endsWith(".js"));
for (const file of command_files){
console.log(file);
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.on("ready", () => {
console.log("Ready to go sir !");
});
client.on("message", message => {
try {
// Check if message is a command
if (!message.content.startsWith(prefix)){
return;
}
const args = message.content
.slice(prefix.length)
.trim()
.split(/ +/);
const commandName = args.shift().toLowerCase();
// Check if there is such a command
if (!client.commands.has(commandName)){
return;
}
const command = client.commands.get(commandName);
// Check the requirements of the command
let adminRole;
if (message.guild !== null) {
adminRole = message.guild.roles.cache.get("763319365625970689"); //758939878288261132
}
if (command.guildOnly && message.channel.type === "dm") {
throw `This command cannot run via direct message.`;
}
if (command.channelOnly) {
if (message.channel.type === "dm") {
if (!command.dmAvailable) {
throw `Bu komut özel mesaj yoluyla çalışmamaktadır !`;
}
} else {
if (message.channel.name !== command.channel) {
throw `Bu komut sunucuda sadece **${command.channel}** kanalında çalışmaktadır !`;
}
}
}
if (
command.adminOnly &&
!message.member.roles.cache.array().includes(adminRole)
) {
throw `This command is only for admin's usage !`;
}
// Execute the command
let ops = {
active: active
};
command.execute(message, args,client, ops)
if(!message.guild.me.voice.channel) return;
if(ops.active.size) return;
let timeoutID;
timeoutID = setTimeout(function(){
message.guild.me.voice.channel.leave();
}, 10);
} catch (err) {
console.log(err);
}
});
client.login(token);