-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathapp.js
More file actions
99 lines (82 loc) · 2.8 KB
/
app.js
File metadata and controls
99 lines (82 loc) · 2.8 KB
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
const { owner, admins, support, invite, prefix, errorLogChannel } = require('./config');
const DBL = require('dblapi.js');
/** Check node.js version is above 10 */
if (Number(process.version.slice(1).split('.')[0]) < 12) throw new Error('Node 12.0.0 or higher is required. Update Node on your system.');
const { Client, version } = require('./src/index');
const client = new Client({
disableEveryone: true,
messageCacheLifetime: 300,
messageSweepInterval: 300,
messageCacheMaxSize: 100,
ws: {
intents: ['GUILDS', 'GUILD_MESSAGES', 'DIRECT_MESSAGES']
},
commandPrefix: prefix,
owner: owner,
commandEditableDuration: 0,
invite: invite,
errorLogChannel: errorLogChannel
});
const init = async function() {
client.version = version;
client.login(client.token);
}
client.on('debug', function(d) {
try {
client.shard.send({ type: 'debug', message: d });
} catch (e) {
console.error(e);
}
});
client.on('warn', function(e) {
try {
client.shard.send({ type: 'warn', message: e });
} catch (e) {
console.error(e);
}
});
client.on('error', function(e) {
try {
if (client.options.errorLogChannel) {
let errorEmbed = client._constructErrorEmbed(e);
client.channels.fetch(client.options.errorLogChannel).then(channel => { if(channel) channel.send('', errorEmbed) });
}
client.shard.send({ type: 'error', message: e.stack || e });
} catch (e) {
console.error(e);
}
});
client.on('ready', function() {
client.user.setActivity(`${client.commandPrefix}help & ${client.commandPrefix}invite`, { type: 'LISTENING' });
client.emit('debug', `client ready and listening to; ${client.guilds.cache.size} guilds and ${client.channels.cache.filter(c => c.type === 'text').size} channels.`);
});
client.on('guildCreate', function(guild) {
client.emit('debug', `${client.user.username} successfully added to guild ${guild.name}(${guild.id})`);
});
client.on('rateLimit', function(info) {
client.emit('warn', info);
});
client.on('commandRun', (command, promise, message) => {
if (command.unknown) return;
if (promise && promise.then) {
promise.then(() => {
if (message.deletable) message.delete({ reason: 'Command Recognised' });
});
} else {
if (message.deletable) message.delete({ reason: 'Command Recognised' });
}
});
if (process.env.DBL_TOKEN) {
const dbl = new DBL(process.env.DBL_TOKEN, client);
dbl.on('posted', () => {
client.emit('debug', `Server count posted to DBL`);
});
dbl.on('error', (e) => {
client.emit('error', e);
});
}
// handle all unhandled promise rejections and print the stack trace
process.on('unhandledRejection', error => {
console.error(error);
});
init();