-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
102 lines (68 loc) · 3.15 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
102
const Discord = require('discord.js');
const bot = new Discord.Client();
const mongoose = require('mongoose');
mongoose.connect('mongodb+srv://coughyyee:[email protected]/Data', {
useUnifiedTopology: true,
useNewUrlParser: true,
useFindAndModify: false
}).then(console.log('Connected to mongo!'))
const { token } = require('./config.json');
const { readdirSync, read } = require('fs');
const ms = require('ms');
const { join } = require('path');
//levels
const Levels = require('discord-xp');
Levels.setURL("mongodb+srv://coughyyee:[email protected]/Data")
const config = require('./config.json');
bot.config = config;
bot.commands = new Discord.Collection();
const commandFolders = readdirSync('./commands');
const Timeout = new Discord.Collection();
const prefix = '.';
//this prefix can be what ever you want ;)
bot.on('ready', () => {
console.log("Ready!")
})
//------------------------------------------------------------------------------
for (const folder of commandFolders) {
const commandFiles = readdirSync(`./commands/${folder}`).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${folder}/${file}`);
bot.commands.set(command.name, command);
}
}
bot.on("error", console.error);
//------------------------------------------------------------------------------
bot.on("message", async (message) => {
if (message.author.bot) return;
if (message.channel.type === 'dm') return; //optional#
//Levels
const randomAmountOfXp = Math.floor(Math.random() * 29) + 1; // Min 1, Max 30
const hasLeveledUp = await Levels.appendXp(message.author.id, message.guild.id, randomAmountOfXp);
if (hasLeveledUp) {
const user = await Levels.fetch(message.author.id, message.guild.id);
message.channel.send(`${message.author}, congratulations! You have leveled up to **${user.level}**!`);
}
//
if (message.content.startsWith(prefix)) {
const args = message.content.slice(prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
const command = bot.commands.get(commandName) || bot.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));
if (!command) return;
if (command) {
if (command.cooldown) {
if (Timeout.has(`${command.name}${message.author.id}`)) return message.channel.send(`Please Wait \`${ms(Timeout.get(`${command.name}${message.author.id}`) - Date.now(), { long: true })}\` Before using this command again!`);
command.run(bot, message, args)
Timeout.set(`${command.name}${message.author.id}`, Date.now() + command.cooldown)
setTimeout(() => {
Timeout.delete(`${command.name}${message.author.id}`)
}, command.cooldown)
} else command.run(bot, message, args);
}
}
})
//--------------------------------------------------------------------------------------------------------------------\\
bot.on("guildMemberAdd", async (member) => {
console.log(member.user.tag);
})
bot.login(token);