-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
92 lines (72 loc) · 3.34 KB
/
main.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
const tStart = +new Date()
const config = require("./config.json")
const token = config.token
const { Client, Collection, Intents } = require('discord.js');
const Discord = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const fs = require('fs');
const colors = require('colors');
client.on('ready', () => {
console.log(colors.green(`${client.user.username} is online and active in ${client.guilds.cache.size} servers!`))
const tEnd = +new Date()
console.log(colors.green(`Init Time: ${tEnd - tStart}ms`))
console.log(colors.green(`////////////////////////////////////////`))
})
client.commands = new Discord.Collection(); //command collection init
client.aliases = new Discord.Collection(); //command alias collection init
fs.readdir("./arc/", (err, files) => { //This block of code reads each .js file in the commands folder and loads it into the commands collection
if(err) console.log(err);
let jsfile = files.filter(f => f.split(".").pop() === "js"); //makes sure each file it loads ends with .js
if(jsfile.length <= 0){
return console.log("no commands found"); //if no commands, it will log this in console. You should never see this
}
jsfile.forEach((f) => {
let props = require(`./arc/${f}`);
console.log(`${f} loaded!`); //Logs this for each file successfully loaded
client.commands.set(props.help.name, props);
props.help.aliases.forEach(alias => {
client.aliases.set(alias, props.help.name);
})
})
})
fs.readdir("./dsc/", (err, files) => { //This block of code reads each .js file in the commands folder and loads it into the commands collection
if(err) console.log(err);
let jsfile = files.filter(f => f.split(".").pop() === "js"); //makes sure each file it loads ends with .js
if(jsfile.length <= 0){
return console.log("no commands found"); //if no commands, it will log this in console. You should never see this
}
jsfile.forEach((f) => {
let props = require(`./dsc/${f}`);
console.log(`${f} loaded!`); //Logs this for each file successfully loaded
client.commands.set(props.help.name, props);
props.help.aliases.forEach(alias => {
client.aliases.set(alias, props.help.name);
})
})
})
client.on("messageCreate", async message => {
if(message.channel.type === "dm") return;
if(message.author.id === client.user.id) return;
let prefixes = JSON.parse(fs.readFileSync("./prefixes.json", "utf8"));
if(!prefixes[message.guild.id]){
prefixes[message.guild.id] = {
prefix: config.prefix
}
}
let prefix = prefixes[message.guild.id].prefix;
if(!message.content.startsWith(prefix)) return;
let args = message.content.slice(prefix.length).trim().split(/ +/g); //splits each arg into a seperate value and into an array to be read later like args[0], args[1]. all depending in if they exist.
let cmd = args.shift().toLowerCase();
let command;
if(client.commands.has(cmd)){
command = client.commands.get(cmd);
} else if(client.aliases.has(cmd)){
command = client.commands.get(client.aliases.get(cmd));
}
try{
command.run(client, message, args); //executes the command
} catch (e){
return;
}
})
client.login(`${token}`)