-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (47 loc) · 1.6 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
const Discord = require("discord.js");
const config = require("./config.json");
const bot = new Discord.Client();
const fs = require("fs");
bot.commands = new Discord.Collection();
var express = require("express");
var app = express();
const token = process.env.TOKEN;
const PORT = process.env.PORT || 8080;
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!`);
bot.commands.set(props.help.name, props);
});
});
bot.on("ready", () => {
console.log(bot.user.username + " is online.");
// console.log(process.env.TOKEN);
});
bot.on("message", async (message) => {
//a little bit of data parsing/general checks
if (message.author.bot) return;
if (message.channel.type === "dm") return;
let content = message.content.split(" ");
let command = content[0];
let args = content.slice(1);
let prefix = config.prefix;
//checks if message contains a command and runs it
let commandfile = bot.commands.get(command.slice(prefix.length));
if (commandfile) commandfile.run(bot, message, args);
});
bot.login(token);
app.set("view engine", "html");
app.listen(PORT, () => {
console.log(`Server running at port: ${PORT}`);
});
// respond with "hello world" when a GET request is made to the homepage
app.get("/", function (req, res) {
res.render("hello world");
});