-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
84 lines (72 loc) · 2.3 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
const mongoose = require('mongoose')
require('dotenv').config()
const fs = require('fs');
const Discord = require('discord.js');
const chalk = require('chalk');
const client = new Discord.Client();
require('discord-buttons')(client);
mongoose.connect(process.env.MONGOPATH_SRV, {
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: false
}).then(() => {
console.log('[DATABASE] Connected to mongodb!')
}).catch((err) => {
console.log(err)
})
client.commands = new Discord.Collection();
const empty = '';
const prefix = 'p~';
client.on('ready', () => {
client.user.setActivity('Currently in Beta | Shard 293', { type: 'WATCHING'}).catch(console.error)
console.log('Total Shards: 342 Shards')
console.log('Total Shards Online: 185')
console.log('Current Shard: 293')
console.log('All Commands currently fully functional!')
console.log('Current Status: WATCHING')
});
function formatLog(msg, type) {
if (type == 0) {
return chalk.gray(empty.concat('[DEBUG] ', msg));
} else if (type == 1) {
return chalk.blue(empty.concat('[INFO] ', msg));
} else if (type == 2) {
return chalk.yellow(empty.concat('[WARNING] ', msg));
} else if (type == 3) {
return chalk.red(empty.concat('[ERROR] ', msg));
} else {
console.log(chalk.red('[ERROR] Invalid log type specified.'));
}
}
const commandFolders = fs.readdirSync('./cmds');
for (const folder of commandFolders) {
const commandFiles = fs
.readdirSync(`./cmds/${folder}`)
.filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./cmds/${folder}/${file}`);
client.commands.set(command.name, command);
}
}
client.once('ready', () => {
});
client.on('message', message => {
const args = message.content.slice(prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
if (!client.commands.has(commandName)) return;
const command = client.commands.get(commandName);
try {
command.execute(message, args);
} catch (error) {
console.log(formatLog(error, 3));
message.reply(
empty.concat('Unable to execute command ', commandName, ': ' + error)
);
}
});
client.on('clickButton', async (button) => {
if(button.id === 'button1') {
await button.reply.send('I know right?', true)
}
});
client.login(process.env.TOKEN);