-
Notifications
You must be signed in to change notification settings - Fork 38
/
index.js
85 lines (60 loc) · 2.32 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
const { promisify } = require('util');
const { Client, Collection } = require('discord.js');
const process = require('process');
const glob = require('glob');
const client = new Client({ intents: 14335, partials: [ 'CHANNEL', 'USER', 'MESSAGE' ] });
const config = require('./config.json');
// Não é recomendado usar config.json na replit, use Secrets 🔒 ao invés disso
require('colors');
const { connect } = require('mongoose');
connect(config.mongo_key)
.then(() => console.log('Conectado com sucesso ao banco de dados'))
.catch(err => console.log('Erro ao conectar ao banco de dados: ', err));
client.commands = new Collection();
client.prefixoPadrao = config.prefix;
const globPromise = promisify(glob);
const pastaComandos = './commands';
const pastaEventos = './events';
client.once('ready', async () => {
const comandos = await globPromise(`${pastaComandos}/**/*.js`);
const eventos = await globPromise(`${pastaEventos}/**/*.js`);
for (const cmd of comandos) {
const command = require(cmd);
// console.log(cmd);
client.commands.set(command.name, command);
console.log(`${command.name.green} carregado`);
}
for (const evento of eventos) {
const evt = require(evento);
client.on(evt.name, (...args) => evt.execute(...args));
console.log(`${evt.name.yellow} carregado`);
}
console.log('*'.repeat(15));
console.log(`${client.user.tag.cyan} online`);
});
// client.on('debug', console.log);
client.login(config.token);
client.on('messageCreate', async message => {
if (message.author.bot) return;
if (!message.content.toLowerCase().startsWith(message.client.prefixoPadrao.toLowerCase())) return;
const args = message.content.slice(message.client.prefixoPadrao.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
const cmd = message.client.commands.get(command);
if (!cmd) return;
try {
await cmd.run(message.client, message, args);
}
catch (error) {
console.log('Error: ', error);
}
});
process.on('unhandledRejection', reason => {
console.log('\n');
console.log(reason);
});
process.on('uncaughtException', (err, origin) => {
console.log('Erro: ');
console.log(err);
console.log('Origem do erro: ');
console.log(origin);
});