-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
68 lines (46 loc) · 1.58 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
const Discord = require('discord.js');
const client = new Discord.Client();
const fs = require('fs');
const { join } = require('path');
const config = require('./config.json');
const prefix = (config.prefix)
const token = (config.token)
const mysql = require("mysql")
client.commands= new Discord.Collection();
const commandFiles = fs.readdirSync(join(__dirname, "commands")).filter(file => file.endsWith(".js"));
for (const file of commandFiles) {
const command = require(join(__dirname, "commands", `${file}`));
client.commands.set(command.name, command);
}
client.on("error", console.error);
client.on('ready', () => {
console.log('bot is ready');
});
var con = mysql.createConnection({
host: 'eu-cdbr-west-03.cleardb.net', // process.env.host
user: 'bcdcd59827cadf', // process.env.user
password: '57a572e0', // process.env.password
database: 'heroku_4ebbd35da0db6b2' // process.env.database
});
con.connect(err => {
if(err) throw err;
console.log('mysql connected')
})
setInterval(function () {
con.query(`SELECT 1`);
}, 5000);
client.on("message", async message => {
if(message.author.bot) return;
if(message.channel.type === 'dm') return;
if(message.content.startsWith(prefix)) {
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if(!client.commands.has(command)) return;
try {
client.commands.get(command).run(client, message, args,con);
} catch (error){
console.error(error);
}
}
})
client.login(token) // process.env.token)