-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
32 lines (27 loc) · 1023 Bytes
/
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
const TOKEN = process.env.TOKEN
const { Client, Intents } = require('discord.js')
const CronJob = require('cron').CronJob
const fs = require('fs')
const path = require('path')
const client = new Client({ intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_MEMBERS,
] })
const scriptsPath = path.join(__dirname, 'scripts')
const scriptFiles = fs.readdirSync(scriptsPath).filter(file => file.endsWith('.js'))
for (const file of scriptFiles) {
const filePath = path.join(scriptsPath, file)
const script = require(filePath)
client.on(script.trigger, script.execute(client))
}
const cronPath = path.join(__dirname, 'cron')
const cronFiles = fs.readdirSync(cronPath).filter(file => file.endsWith('.js'))
for (const file of cronFiles) {
const filePath = path.join(cronPath, file)
const cron = require(filePath)
const job = new CronJob(cron.schedule, cron.execute(client), null, true, cron.timezone)
job.start()
}
client.login(TOKEN)