-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
56 lines (47 loc) · 1.42 KB
/
bot.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
require("dotenv").config();
const Discord = require("discord.js");
const fs = require("fs");
const express = require("express");
const cors = require("cors");
const http = require("http");
const client = new Discord.Client();
const config = require("./config.js");
client.config = config;
client.playing = false;
const app = express();
const port = process.env.PORT || 3000;
const webhooks = require("./handlers/webhooks");
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(cors());
app.get("/", (req, res) => res.status(200).send("Hello World!"));
app.use(
"/",
(req, res, next) => {
req.client = client;
next();
},
webhooks
);
app.listen(port, () => console.log(`Server listening on port ${port}`));
fs.readdir("./events/", (err, files) => {
if (err) return console.error(err);
files.map((file) => {
let event = require(`./events/${file}`);
let eventName = file.split(".")[0];
client.on(eventName, event.bind(null, client));
});
});
client.commands = new Discord.Collection();
fs.readdir("./commands/", (err, files) => {
if (err) return console.error(err);
console.log("[Commands] Loading...");
files.map((file) => {
if (!file.endsWith(".js")) return;
let props = require(`./commands/${file}`);
console.log(`[Commands] Loaded ${file}`);
client.commands.set(props.help.name, props);
});
console.log(`[Commands] Loaded ${files.length} commands!`);
});
client.login(client.config.token);