This repository has been archived by the owner on Aug 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.ts
72 lines (67 loc) · 2.04 KB
/
index.ts
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
/* eslint-disable @typescript-eslint/no-var-requires */
import { promises as fs } from 'fs';
import { join } from 'path';
import { registerFont } from 'canvas';
import { ClientEvents, Constants, Extendable, Intents, Structures } from 'discord.js';
import Client from './util/Client';
registerFont(join(__dirname, 'assets', 'fonts', 'BebasNeue-Bold.ttf'), {
family: 'bebas-neue'
});
const extended: (keyof Extendable)[] = [
'Message', 'Guild'
];
for (const className of extended) {
Structures.extend(className, () => require(join(__dirname, 'structures', 'discord.js', className)).default);
}
const config = require(join(__dirname, 'config.json'));
const client = new Client(config, {
allowedMentions: {
parse: []
},
partials: ['REACTION', 'MESSAGE'],
presence: {
activity: {
name: `${config.prefix[0]}help`
}
},
ws: {
intents: Intents.ALL
}
});
client.on('error', console.error);
client.on('warn', console.warn);
/**
* These events should be put in place to handle the `Guild#invites` and `Guild#bans`
* properties added in the custom extended Guild structure
* `user` shouldn't be a partial, so it is typed as such
*/
client.on(Constants.Events.GUILD_BAN_ADD, async (guild, user) => {
if (guild.bans.has(user.id)) return;
try {
const ban = await guild.fetchBan(user.id);
guild.bans.set(user.id, ban);
} catch {
client.emit('warn', 'Recieved an error fetching a ban in the \'guildBanAdd\' event, this should not happen');
}
});
client.on(Constants.Events.GUILD_BAN_REMOVE, (guild, user) => {
guild.bans.delete(user.id);
});
client.connect();
/**
* `events` should be a folder in the root directory of bot
* this may become configurable at a later date
*/
fs.readdir(join(__dirname, 'events')).then(files => {
for (const file of files) {
if (!file.endsWith('.js')) return;
const fn: (...args: unknown[]) => void = require(
join(__dirname, 'events', file)
).default;
client.on(file.split('.')[0] as keyof ClientEvents, fn);
}
}, err => {
console.error(err);
process.exit(1);
});
client.on('ready', () => console.log('Ready'));