-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
48 lines (37 loc) · 1.33 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
// Initialize
require('dotenv').config();
const Cron = require('node-cron');
const chzzkNotifier = require('./lib/chzzk');
// Extract the required classes from the discord.js module
const { Client, Events, GatewayIntentBits, REST } = require('discord.js');
const { sequelize } = require('./lib/db');
// Create a new client instance
const client = new Client({
intents: [GatewayIntentBits.Guilds],
});
const token = process.env.TOKEN;
// Construct and prepare an instance of the REST module
const rest = new REST({ version: '10' }).setToken(token);
// CHZZK Notifier
const { user_list } = require('./config.json')
// When the client is ready, run this code (only once)
// We use 'c' for the event parameter to keep it separate from the already defined 'client'
client.once(Events.ClientReady, async (c) => {
// initialize db
await sequelize.sync({ force: false })
.then(() => {
console.log('[DB] Connected to Database');
})
.catch((e) => {
console.log('[DB] Failed to connect');
console.error(e.message);
});
Cron.schedule('* * * * *', async () => {
for (const uid of user_list) {
await chzzkNotifier(c, uid);
}
});
console.log(`[Discord] Logged in as ${c.user.tag}`);
});
// Log in to Discord with your client's token
client.login(token);