-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
67 lines (59 loc) · 2.29 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
//Importing modules and required files
const config = require("./config.json");
const Discord = require("discord.js");
const bot = new Discord.Client({ disableEveryone: true });
//DISCORDBOTS.ORG SERVER COUNT API
//-------------------------------------------------------------\\
const DBL = require("dblapi.js");
const dbl = new DBL(config.dblApi, bot);
dbl.on("posted", () => {
console.log("Server count posted on discordbots.org!");
});
dbl.on("error", e => {
console.log(`Error connecting with discordbots.org`);
});
//-------------------------------------------------------------\\
//Command Handler
const fileSys = require("fs");
bot.commands = new Discord.Collection();
fileSys.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 In Commands Folder");
return;
}
jsFile.forEach((f, i) => {
let props = require(`./commands/${f}`);
console.log(`${f} loaded!`);
bot.commands.set(props.help.name, props);
});
});
//Ready message when bot successfully loads
bot.on("ready", async () => {
console.log(
`${bot.user.username} is online! Running on ${bot.guilds.size} servers!`
);
let status = [`from Kanna's Laptop`, `${bot.guilds.size} servers | .help`];
status_change(status); //Random status displays
});
bot.on("message", async message => {
if (message.author.bot) return; //Don't respond to messages made by the bot
if (message.channel.type == "dm") return; //Don't respond to dm's sent to the bot
//Variable declarations
let prefix = config.prefix;
let msgarray = message.content.split(" "); //Splits the msg everytime there is a space
let cmd = msgarray[0]; //Assigns the first word in msg to cmd variable. Ex: "!play"
let args = msgarray.slice(1); //Cuts off the cmd part of the msg and assigns the rest to args variable
if (cmd.charAt(0) == prefix) {
let commandFile = bot.commands.get(cmd.slice(prefix.length));
if (commandFile) commandFile.run(bot, message, args); //Run commands
}
});
bot.login(config.token);
function status_change(status) {
setInterval(function () {
let chosen = status[Math.floor(Math.random() * status.length)];
bot.user.setActivity(`${chosen}`, { type: "Watching" });
}, 10000);
}