-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
70 lines (66 loc) · 2.26 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
const Discord = require('discord.js');
const fs = require("fs");
const path = require('path');
const config = require("./config.json");
const client = new Discord.Client();
const TeemoJS = require('teemojs');
const sqlite3 = require('sqlite3').verbose();
const wordReacter = require('./bot/wordReacter.js');
const levelHandler = require('./bot/levelsystem/levelhandler.js');
const dl = require('discord-leveling');
const talkedRecently = new Set();
client.commands = new Discord.Collection();
client.config = config;
client.lolApi = TeemoJS(config.league_token);
client.once('ready', () => {
client.user.setPresence({
game: {
name: config.bot_activity,
type: 'PLAYING'
},
status: 'idle'
})
console.log('Bot started');
});
const commandFiles = fs.readdirSync('./bot/commands/');
for (const folder of commandFiles) {
const commandFolder = fs.readdirSync(`./bot/commands/${folder}/`)
for (const file of commandFolder) {
const command = require(`./bot/commands/${folder}/${file}`)
client.commands.set(command.name, command);
}
}
client.on("guildMemberAdd", member =>{
member.setRoles([config.join_role]);
});
//reading the messages in discord
client.on('message', async message => {
if(!message.author.bot) //don't want bots to level
levelHandler.addExp(message);
if (!message.content.startsWith(client.config.prefix) && !message.author.bot) {
wordReacter.execute(message);
if(config.complain)
client.commands.get('complain').execute(message,undefined);
return;
}
if (talkedRecently.has(message.author.id)) {
message.channel.send("Wait 20 seconds before using a new command. - " + message.author);
return;
}
const args = message.content.slice(client.config.prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if (!client.commands.has(command))
return;
try {
client.commands.get(command).execute(message, args);
talkedRecently.add(message.author.id);
setTimeout(() => {
talkedRecently.delete(message.author.id);
}, 20000);
}
catch (error) {
console.error(error);
message.reply(error);
}
});
client.login(config.token);