-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
73 lines (56 loc) · 2.13 KB
/
server.js
File metadata and controls
73 lines (56 loc) · 2.13 KB
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
// server.js
// where your node app starts
// we've started you off with Express (https://expressjs.com/)
// but feel free to use whatever libraries or frameworks you'd like through `package.json`.
require("dotenv").config()
const express = require("express");
const app = express();
const fs = require('fs')
const Discord = require('discord.js');
const client = new Discord.Client()
client.commands = new Discord.Collection()
client.cooldowns = new Discord.Collection()
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
const config= require("./config.js")
client.once('ready', () => {
console.log("ready!")
})
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.on("message", msg => {
if (!msg.content.startsWith(config.prefix) || msg.author.bot) return;
const args = msg.content.slice(config.prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (!client.commands.has(command)) return;
try {
client.commands.get(command).execute(msg, args, client);
} catch (error) {
console.error(error);
msg.reply('There was an error trying to execute that command! Ignore this if the command works but consult **qhelp** if you are actually having a problem.');
}
})
// our default array of dreams
// const dreams = [
// "Find and count some sheep",
// "Climb a really tall mountain",
// "Wash the dishes"
// ];
// make all the files in 'public' available
// https://expressjs.com/en/starter/static-files.html
app.use(express.static("public"));
// // https://expressjs.com/en/starter/basic-routing.html
app.get("/", (request, response) => {
response.sendFile(__dirname + "/views/index.html");
});
// send the default array of dreams to the webpage
// app.get("/dreams", (request, response) => {
// // express helps us take JS objects and send them as JSON
// response.json(dreams);
// });
client.login(process.env.BOT_TOKEN)
// listen for requests :)
const listener = app.listen(process.env.PORT, () => {
console.log("Your app is listening on port " + listener.address().port);
});