-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (48 loc) · 1.68 KB
/
index.js
File metadata and controls
61 lines (48 loc) · 1.68 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
const { Client, Collection } = require('discord.js')
const fs = require('fs')
const client = new Client({
intents: 32767,
partials: ['CHANNEL','MESSAGE']
})
const prefix = `?`
const mongoose = (global.mongoose = require('mongoose'))
const express = require('express');
const app = express()
client.commands = new Collection()
app.listen(300, () => {
console.log('Project running')
})
app.get('/', (req,res) => {
res.send('Listening to port 3000')
})
const commandHandler = fs.readdirSync("./Commands")
for(file of commandHandler){
if(!file.endsWith(".js")) {
fs.readdirSync("./Commands").filter(file => !file.endsWith(".js")).forEach(dir => {
const f = fs.readdirSync(`./Commands/${dir}`).filter(file => file.endsWith(".js"))
f.forEach(x => {
let commandName = x.split(".")[0]
let command = require(`./Commands/${dir}/${commandName}`)
client.commands.set(command.name, command)
})
})
}
if(file.endsWith(".js")) {
let commandName = file.split(".")[0]
let command = require(`./Commands/${commandName}`)
client.commands.set(command.name, command)
}
}
client.on("messageCreate", async message => {
if (message.content.startsWith(prefix)){
const args = message.content.slice(prefix.length).trim().split(/ +/g)
const commandName = args.shift()
const command = client.commands.find(cmd => cmd.name.includes(commandName))
if(!command) return;
command.run(client, message, args)
}
})
const mongooseConnectionString = (process.env.mongooseConnectionString)
if (!mongooseConnectionString) return;
mongoose.connect(mongooseConnectionString).then(() => console.log('Connected to mongodb'));
client.login(process.env.token)