-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
101 lines (89 loc) · 2.69 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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const fs = require("fs");
const { Client, Intents } = require("discord.js");
const cron = require("node-cron");
const mysql = require("mysql2");
require("dotenv").config();
//Discord Settings
const client = new Client({
intents: [Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILDS],
});
module.exports = client;
const prefix = process.env.PREFIX;
//Commands Read
const commands = {};
const commandFiles = fs
.readdirSync("./commands")
.filter((file) => file.endsWith(".js"));
for (const e of commandFiles) {
const command = require(`./commands/${e}`);
commands[command.data.name] = command;
}
client.on("ready", async () => {
console.log(`${client.user.tag} is ready!`);
//Scheduler
cron.schedule("0 0 0 * * *", () => {
const s = "update users set dc = 5";
const connection = mysql.createConnection({
host: process.env.DB_HOST,
password: process.env.DB_PASS,
user: process.env.DB_USER,
database: process.env.DB_NAME,
ssl: {
rejectUnauthorized: true,
},
supportBigNumbers: true,
bigNumberStrings: true,
});
try {
connection.connect();
connection.query(s, function (err, res, fields) {
if (err) throw err
client.channels.cache
.get(process.env.BOT_CH)
.send(
"```"+
`${
new Date().getMonth() + 1
}月${new Date().getDate()}日のデイリーリワードが正常に配布されました。` + "```"
);
connection.end();
});
connection.query("select * from users order by pc desc limit 5", function(err, res, fields) {
if (err) throw err
client.channels.cache
.get(process.env.BOT_CH)
.send({
embeds: [
{
author: {
name: "KRA",
url: "https://discord.gg/GQvCEJCdCn"
},
title: "Ranking",
description:
`1st : <@${res[0].id}> ${res[0].pc}PC\n`+
`2nd : <@${res[1].id}> ${res[1].pc}PC\n`+
`3rd : <@${res[2].id}> ${res[2].pc}PC\n`+
`4th : <@${res[3].id}> ${res[3].pc}PC\n`+
`5th : <@${res[4].id}> ${res[4].pc}PC\n`
}
]
})
})
} catch (e) {
console.log(e);
}
});
});
client.on("messageCreate", async (msg) => {
if (!msg.content.startsWith(prefix)) return;
if (msg.author.bot) return;
const cmd = commands[msg.content.split(" ")[0].substring(prefix.length)];
try {
await cmd.execute(msg);
} catch (e) {
msg.reply("```エラーが発生しました```");
console.log(e);
}
});
client.login(process.env.BOT_TOKEN);