-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathindex.js
66 lines (54 loc) · 1.83 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
const config = require("./config.json");
const Discord = require("discord.js");
const fs = require("fs");
const client = new Discord.Client({ disableEveryone: true });
const prefix = config.prefix;
const token = config.token;
bot.commands = new Discord.Collection();
bot.aliases = new Discord.Collection();
fs.readdir("./commands/", (err, files) => {
if (err) console.log(err);
let jsfile = files.filter(f => f.split(".").pop() === "js");
if (jsfile.length <= 0) {
console.log("Couldn't find commands.");
return;
}
jsfile.forEach((f, i) => {
let props = require(`./commands/${f}`);
console.log(`${f} loaded!`);
client.commands.set(props.help.name, props);
props.help.aliases.forEach(alias => {
client.aliases.set(alias, props.help.name);
});
});
});
client.on("ready", async () => {
console.log(`${client.user.username} is ready for action!`);
if (config.activity.streaming == true) {
client.user.setActivity(config.activity.game, {url: 'https://twitch.tv/username'});
} else {
client.user.setActivity(config.activity.game, {type: 'WATCHING'}); // PLAYING, LISTENING, WATCHING, STREAMING
client.user.setStatus('dnd'); // dnd, idle, online, invisible
}
});
client.on("message", async message => {
if (message.author.bot) return;
if (message.channel.type === "dm") return;
let messageArray = message.content.split(" ");
let args = message.content
.slice(prefix.length)
.trim()
.split(/ +/g);
let cmd = args.shift().toLowerCase();
let commandfile;
if (client.commands.has(cmd)) {
commandfile = client.commands.get(cmd);
} else if (client.aliases.has(cmd)) {
commandfile = client.commands.get(client.aliases.get(cmd));
}
if (!message.content.startsWith(prefix)) return;
try {
commandfile.run(client, message, args);
} catch (e) {}
});
client.login(token);