-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
50 lines (45 loc) · 1.53 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
require('dotenv').config();
import { Intents, Client, Message } from 'discord.js';
import { handleIncomingChannelCommand } from './src/controllers/incomingMessageHandler';
import { assignRoleByCode } from './src/helper/assignRolebyCode';
import { assignRoleOnIntroduction } from './src/helper/assignRolebyIntro';
import { handleMemberJoin } from './src/helper/memberLogs';
import { COMMANDS, CONSTANTS } from './src/utils/constants';
import { initDbClient } from './src/utils/database';
(async () => {
initDbClient();
const client = new Client({ intents: new Intents(32767) });
client.login(process.env.TOKEN);
client.on('ready', () => console.log('Bot is online!'));
client.on('messageCreate', async (message: Message) => {
try {
if (!message.author.bot) {
if (message.content.split(/\s+/)[0] == COMMANDS.prefix) {
switch (message.channel.type) {
case 'GUILD_TEXT': {
handleIncomingChannelCommand(message);
break;
}
default: {
console.log(`Channel not supported`);
}
}
return;
}
if (message.channelId === CONSTANTS.CODE_CHANNEL_ID) {
assignRoleByCode(message);
return;
}
if (message.channelId === CONSTANTS.INTRODUCE_CHANNEL_ID) {
assignRoleOnIntroduction(message);
return;
}
}
} catch (err) {
console.log(err);
}
});
client.on('guildMemberAdd', (member: any) => {
handleMemberJoin(member);
});
})();